|
|
Line 173: |
Line 173: |
|
| |
|
| === Search and Execution === | | === Search and Execution === |
| There are three types of commands: shell functions, builtin commands, and normal programs – and the
| | コマンドには、シェル関数、組み込みコマンド、通常のプログラムの3種類があり、この順番でコマンドを(名前で)検索する。 それぞれ異なる方法で実行される。 |
| command is searched for (by name) in that order. They each are executed in a different way.
| |
|
| |
|
| When a shell function is executed, all of the shell positional parameters (except $0, which remains
| | シェル関数が実行されると、シェルの位置パラメーターはすべて(変更されない$0を除く)シェル関数の引数に設定される。 コマンドの環境に明示的に置かれた変数(関数名の前に変数への代入を置く)は、その関数のローカルとなり、与えられた値に設定される。 次に,関数定義で与えられたコマンドが実行される. コマンドの実行が完了すると、位置パラメータは元の値に戻される. これはすべて現在のシェル内で行われる。 |
| unchanged) are set to the arguments of the shell function. The variables which are explicitly placed
| |
| in the environment of the command (by placing assignments to them before the function name) are made
| |
| local to the function and are set to the values given. Then the command given in the function defini‐
| |
| tion is executed. The positional parameters are restored to their original values when the command
| |
| completes. This all occurs within the current shell.
| |
|
| |
|
| Shell builtins are executed internally to the shell, without spawning a new process.
| | シェルのビルトインは、新しいプロセスを生成することなく,シェルの内部で実行される。 |
|
| |
|
| Otherwise, if the command name doesn't match a function or builtin, the command is searched for as a
| | それ以外の場合、コマンド名が関数やビルトインにマッチしない場合、コマンドはファイルシステム内の通常のプログラムとして検索される(次のセクションで説明する)。 通常のプログラムが実行されると、シェルは引数や環境をプログラムに渡して実行する。 プログラムが通常の実行可能なファイルでない場合(すなわち、ASCII表現が "#!"である「マジックナンバー」で始まらないので、''[https://manpages.debian.org/testing/manpages-dev/execve.2.en.html execve]''(2)がENOEXECを返す場合)、シェルは子シェルでプログラムを解釈することになる。 この場合、子シェルはそれ自体を再初期化するので、親シェルにあるハッシュ化されたコマンドの位置が子シェルによって記憶されることを除いて、アドホックなシェルスクリプトを扱うために新しいシェルが起動されたかのような効果がある。 |
| normal program in the file system (as described in the next section). When a normal program is exe‐
| |
| cuted, the shell runs the program, passing the arguments and the environment to the program. If the
| |
| program is not a normal executable file (i.e., if it does not begin with the "magic number" whose
| |
| ASCII representation is "#!", so execve(2) returns ENOEXEC then) the shell will interpret the program
| |
| in a subshell. The child shell will reinitialize itself in this case, so that the effect will be as
| |
| if a new shell had been invoked to handle the ad-hoc shell script, except that the location of hashed
| |
| commands located in the parent shell will be remembered by the child.
| |
|
| |
|
| Note that previous versions of this document and the source code itself misleadingly and sporadically
| | この文書の以前のバージョンとソースコード自体は、マジックナンバーのないシェルスクリプトを「シェルプロシージャ」と誤解を招くような散発的な表現をしていることに注意されたい。 |
| refer to a shell script without a magic number as a "shell procedure".
| |
|
| |
|
| === Path Search === | | === Path Search === |