Skip to content

Instantly share code, notes, and snippets.

@mugyu
Last active December 26, 2018 06:54
Show Gist options
  • Save mugyu/8ee26557ff8f6d7a8961fcdd6f7d4288 to your computer and use it in GitHub Desktop.
Save mugyu/8ee26557ff8f6d7a8961fcdd6f7d4288 to your computer and use it in GitHub Desktop.
実行するコマンド以外に影響を与える事無く環境変数を設定する on bash

bashで、 実行するコマンド以外に影響を与える事無く、環境変数を設定する

env 環境変数=値 コマンド
環境変数=値 コマンド

でもいけるらしい。けど、これは環境変数ではなくてシェル変数のような気もするけど……

$ cat test1.sh
echo test1=$HOGE
bash ./test2.sh
$ cat test2.sh
echo test2=$HOGE
$ HOGE=hoge bash test1.sh
test1=hoge
test2=hoge

試してみたら普通に子プロセスにも渡っていたので、スコープ的には問題ないのかな

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment