11
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

.env ( dotenv ) ファイルの定義をシェルの環境変数として export するコマンドの例 ( set -a; source .env; set +a; ) #Linux #Shell

Last updated at Posted at 2020-03-03

Command

set -a; source .env; set +a;

Example

echo "EXAMPLE1=ABC\nEXAMPLE2=DEF" >> .env

cat .env
EXAMPLE1=ABC
EXAMPLE2=DEF

env | grep EXAMPLE

set -a; source .env; set +a;

env | grep EXAMPLE
EXAMPLE1=ABC
EXAMPLE2=DEF

set -a とは

set -a で変数定義を、環境変数定義である export 扱いにできるようだ。
それを source コマンドで、シェルの「表側」で実行する。

NAME
    set - Set or unset values of shell options and positional parameters.

SYNOPSIS
    set [--abefhkmnptuvxBCHP] [-o option-name] [arg ...]

DESCRIPTION
    Set or unset values of shell options and positional parameters.
    
    Change the value of shell attributes and positional parameters, or
    display the names and values of shell variables.
    
    Options:
      -a  Mark variables which are modified or created for export.

Linux — source コマンドは何をしているのか > 実は環境をリロードするためのものではない - Qiita

Original by Github issue

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

11
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?