「Transwiki:Bash Shell Scripting」の版間の差分

削除された内容 追加された内容
Fu7mu4 (トーク | 投稿記録)
Fu7mu4 (トーク | 投稿記録)
781 行
変数割り当てと似た文法でこれとは全く異なった効果があります。これを混乱を避けたいのなら、同じ効果を得るために一般的なUnixユーティリティ<tt> env </tt>を使いましょう。このユーティリティは、1つのコマンドの環境変数を ''削除''できます。または1回のコマンドで ''全て''の環境変数を削除できます。)もし<tt> $var </tt>がすでに存在し、かつ実際の値を1つのコマンドだけの実行環境にだけ影響させたい場合、<source lang = "bash" enclose = "none"> var="$var" command </source>として実行できます。
 
An aside: sometimes it's useful to put variable definitions — or function definitions — in one変数の定義や関数の定義をひとつの Bash script スクリプトにまとめておき(say,例えば <tt>header.sh</tt>) that can be called by another、このファイルを他の Bash script スクリプト(say,例えば <tt>main.sh</tt>). We can see that simply invoking that otherから読み込むことを便利だと伝えてきた。しかし、単純に他の Bash script, as スクリプトを起動した場合(例えば<tt>./header.sh</tt> or as <tt>bash ./header.sh</tt>, will not work: the variable definitions in ではうまく動作しない。<tt>header.sh</tt> would not be seen by にある変数の定義は"エクスポート"されていないので、<tt>main.sh</tt>, not even if we "exported" those definitions. から見えないからです。(This is a common point of confusionこれは通常混乱しやすい点です。: <tt>export</tt> exports variables into the environment so that other processes can see them, but they're still only seen by ''child'' processes, not by ''parents''.) However, we can use the Bash built-in command <tt>.</tt> ("dot") or <tt>source</tt>, which runs an external file almost as though it were a shell function. If <tt>header.sh</tt> looks like this:
 
<source lang="bash">foo=bar