/usr/bin/dash: Difference between revisions

Line 245: Line 245:


=== Short-Circuit List Operators ===
=== Short-Circuit List Operators ===
    “&&” and “||” are AND-OR list operators.  “&&” executes the first command, and then executes the sec‐
"&&"と"||"はAND-ORリスト演算子である。 "&&"は、最初のコマンドを実行し、最初のコマンドの終了ステータスがゼロの場合に限り、2番目のコマンドを実行する。 "||"も同様だが、最初のコマンドの終了ステータスがゼロでない場合にのみ、2番目のコマンドを実行する。 "&&"と"||"はどちらも同じ優先度を持つ。
    ond command if and only if the exit status of the first command is zero.  “||” is similar, but exe‐
    cutes the second command if and only if the exit status of the first command is nonzero.  “&&” and
    “||” both have the same priority.


  Flow-Control Constructs – if, while, for, case
フロー制御構文 - if、while、for、case
    The syntax of the if command is
ifコマンドの構文は以下の通りである。


           if list
           if list
Line 260: Line 257:
           fi
           fi


    The syntax of the while command is
whileコマンドの構文は以下の通りである。


           while list
           while list
Line 266: Line 263:
           done
           done


    The two lists are executed repeatedly while the exit status of the first list is zero.  The until com‐
最初のリストの終了ステータスがゼロの間、2つのリストが繰り返し実行される。 untilコマンドも似ているが、whileの代わりにuntilという単語があり、最初のリストの終了ステータスがゼロになるまで繰り返される。
    mand is similar, but has the word until in place of while, which causes it to repeat until the exit
    status of the first list is zero.


    The syntax of the for command is
forコマンドの構文は以下の通りである。


           for variable [ in [ word ... ] ]
           for variable [ in [ word ... ] ]
Line 276: Line 271:
           done
           done


    The words following in are expanded, and then the list is executed repeatedly with the variable set to
inに続く単語が展開され、変数に各単語が順番にセットされた状態でリストが繰り返し実行される。 in word ...を省略すると、in "$@"と同じになる。
    each word in turn.  Omitting in word ... is equivalent to in "$@".


    The syntax of the break and continue command is
break and continueコマンドの構文は以下の通りである。


           break [ num ]
           break [ num ]
           continue [ num ]
           continue [ num ]


    Break terminates the num innermost for or while loops.  Continue continues with the next iteration of
Breakは、最も内側のforまたはwhileループを終了させる。 Continueは、最も内側のループの次の反復を続ける。 これらは組み込みコマンドとして実装されている。
    the innermost loop.  These are implemented as builtin commands.


    The syntax of the case command is
caseコマンドの構文は以下の通りである。


           case word in
           case word in
Line 294: Line 287:
           esac
           esac


    The pattern can actually be one or more patterns (see Shell Patterns described later), separated by
パターンは実際には1つ以上のパターン(後述のシェルパターンを参照)にすることができ、"|"文字で区切られる。 パターンの前の"("文字はオプションである。
    “|” characters.  The “(” character before the pattern is optional.


  Grouping Commands Together
コマンドをグループ化する
    Commands may be grouped by writing either
 
コマンドは


           (list)
           (list)
Line 306: Line 299:
           { list; }
           { list; }


    The first of these executes the commands in a subshell.  Builtin commands grouped into a (list) will
これらのうち最初のものは、サブシェル内のコマンドを実行する。 (リスト)にグループ化された組み込みコマンドは、現在のシェルに影響を与えない。 2番目の形式は、別のシェルをフォークしないので、少し効率的である。 このようにコマンドをグループ化することで、あたかも1つのプログラムであるかのように出力をリダイレクトすることができる:
    not affect the current shell.  The second form does not fork another shell so is slightly more effi‐
    cient.  Grouping commands together this way allows you to redirect their output as though they were
    one program:


           { printf " hello " ; printf " world\n" ; } > greeting
           { printf " hello " ; printf " world\n" ; } > greeting


    Note that “}” must follow a control operator (here, “;”) so that it is recognized as a reserved word
他のコマンド引数としてではなく、予約語として認識されるように、"}"は制御演算子(ここでは";")の後に続かなければならないことに注意。
    and not as another command argument.
 
関数


  Functions
関数定義の構文は以下の通りである。
    The syntax of a function definition is


           name () command
           name () command


    A function definition is an executable statement; when executed it installs a function named name and
実行されると、nameという名前の関数がインストールされ、終了ステータスはゼロを返す。 コマンドは通常、"{"と"}"で囲まれたリストである。
    returns an exit status of zero.  The command is normally a list enclosed between “{” and “}”.


    Variables may be declared to be local to a function by using a local command.  This should appear as
変数は、localコマンドを使用することで、関数に対してlocalであることを宣言することができる。 これは関数の最初のステートメントとして記述する。
    the first statement of a function, and the syntax is


           local [variable | -] ...
           local [variable | -] ...


    Local is implemented as a builtin command.
localは組み込みコマンドとして実装されている。


    When a variable is made local, it inherits the initial value and exported and readonly flags from the
変数をlocalにすると、その変数の初期値、エクスポートとリードオンリーのフラグを、周囲のスコープに同じ名前の変数があれば、その変数から継承する。 そうでない場合、変数は初期値として設定されない。 シェルは動的スコープを使用するため、変数xを関数fのlocalにし、その関数fが関数gを呼び出した場合、gの内部で作成された変数xへの参照は、xという名前のグローバル変数ではなく、fの内部で宣言された変数xを参照することになる。
    variable with the same name in the surrounding scope, if there is one.  Otherwise, the variable is
    initially unset.  The shell uses dynamic scoping, so that if you make the variable x local to function
    f, which then calls function g, references to the variable x made inside g will refer to the variable
    x declared inside f, not to the global variable named x.


    The only special parameter that can be made local is “-”.  Making “-” local any shell options that are
localにできる唯一の特別なパラメーターは"-"である。 localに"-"を指定すると、関数内でsetコマンドによって変更されたシェル・オプションは、関数が戻ったときに元の値に戻される。
    changed via the set command inside the function to be restored to their original values when the func‐
    tion returns.


    The syntax of the return command is
returnコマンドの構文は以下の通りである。


           return [exitstatus]
           return [exitstatus]


    It terminates the currently executing function.  Return is implemented as a builtin command.
現在実行中の関数を終了させる。 returnは組み込みコマンドとして実装されている。


=== Variables and Parameters ===
=== Variables and Parameters ===