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

削除された内容 追加された内容
Fu7mu4 (トーク | 投稿記録)
Fu7mu4 (トーク | 投稿記録)
665 行
==サブシェル、環境変数、スコープ==
 
{{Transwiki:Bash Shell Scripting/caution|この章には時間をかけてください。これらの概念は、一度理解できたあとでは比較的簡単に理解できますが、多くの点で他のプログラミング言語の類似の概念とは異なります。 Bashの経験がある人も含め、多くのプログラマーやシステム管理者は、これを最初に学んだ際には直感に反すると感じると思います。}}
{{Transwiki:Bash Shell Scripting/caution|Take your time with this section. These concepts are relatively straightforward once you understand them, but they are different in important ways from analogous concepts in other programming languages. Many programmers and systems administrators, including some who are experienced in Bash, find them counter-intuitive at first.}}
 
===サブシェル===
 
Bashでは、一つまたは複数のコマンドを丸括弧でつつむことで、それらのコマンドを "サブシェル"で実行できます。(サブシェルを暗黙的に作成する方法があり、後に学べられます。) サブシェルはそれをつつむ コンテキストの''実行環境'' のコピーを受けとります。この実行環境には、変数やそのほかのものを含んでいます。しかしサブシェルが変更または作成した実行環境はサブシェルが完了したあとに元へ戻しません。例をあげます。
In Bash, one or more commands can be wrapped in parentheses, causing those commands to be executed in a "subshell". (There are also a few ways that subshells can be created implicitly; we will see those later.) A subshell receives a copy of the surrounding context's "execution environment", which includes any variables, among other things; but any changes that the subshell makes to the execution environment are ''not'' copied back when the subshell completes. So, for example, this script:
 
<source lang="bash">#!/bin/bash