「Transwiki:Bash Shell Scripting」の版間の差分
削除された内容 追加された内容
801 行
Bashの変数のスコープに不規則な点をいくつか見てきました。要約すると以下のようになります。
* 通常のBash変数の範囲は、それを含むシェル、またはそれに含まれるサブシェルに限定されています。
** 通常のBash変数は子プロセスからは見えません。(外部プログラムからも)
** サブシェルで作成された通常のBash変数は親のシェルからは見えません。
** 通常のBash変数がサブシェル内で修正された場合、その変更は親のシェルからは見えません。
** この挙動は関数でも同じで、通常のBash変数にもあてはまる。
* Function-calls are not inherently run in subshells.
** 関数内での変数の修正は通常、関数を呼び出したコードから ''見え''ます。
* Bash variables that are exported into the environment are scoped to the shell that contains them, including any subshells ''or child processes'' in that shell.
** The <tt>export</tt> built-in command can be used to export a variable into the environment. (There are other ways as well, but this is the most common way.)
|