/usr/bin/bash: Difference between revisions

Line 1,155: Line 1,155:


== COMMAND EXECUTION ==
== COMMAND EXECUTION ==
      After a command has been split into words, if it results in a simple command and an optional list
コマンドが単語に分割された後、それが単純なコマンドとオプションの引数リストになる場合、以下のアクションが実行される。
      of arguments, the following actions are taken.


      If  the  command  name  contains  no slashes, the shell attempts to locate it.  If there exists a
コマンド名にスラッシュが含まれていない場合、シェルはそのコマンドを探そうとする。 その名前のシェル関数が存在する場合、その関数は上記の[[#FUNCTIONS|FUNCTIONS ]]で説明したように呼び出される。 その名前が関数と一致しない場合、シェルはシェル組み込み関数のリストからその関数を検索する。 一致するものが見つかれば、その組み込み関数が呼び出される。
      shell function by that name, that function is invoked as described above in  FUNCTIONS.  If  the
      name  does  not  match a function, the shell searches for it in the list of shell builtins. If a
      match is found, that builtin is invoked.


      If the name is neither a shell function nor a builtin, and contains  no  slashes,  bash  searches
名前がシェル関数でもビルトインでもなく、スラッシュを含まない場合、bashは'''PATH'''の各要素からその名前の実行可能ファイルを含むディレクトリを検索する。 Bashは、実行可能ファイルのフルパス名を記憶するためにハッシュテーブルを使用する(以下の「シェル組み込みコマンド」の「ハッシュ」を参照)。  PATH内のディレクトリの完全な検索は、ハッシュテーブルでコマンドが見つからなかった場合にのみ実行される。 検索に失敗した場合、シェルはcommand_not_found_handleという名前の定義されたシェル関数を検索する。 その関数が存在する場合、元のコマンドと元のコマンドの引数を引数として別の実行環境で呼び出され、その関数の終了ステータスがそのサブシェルの終了ステータスになる。 その関数が定義されていない場合、シェルはエラー・メッセージを表示し、終了ステータス127を返す。
      each element of the PATH for a directory containing an executable file by that name.  Bash uses a
      hash table to remember the full pathnames of executable files (see hash under SHELL BUILTIN  COM‐
      MANDS  below).  A full search of the directories in PATH is performed only if the command is not
      found in the hash table.  If the search is unsuccessful, the shell searches for a  defined  shell
      function  named  command_not_found_handle.  If that function exists, it is invoked in a separate
      execution environment with the original command and the original command's arguments as its argu‐
      ments, and the function's exit status becomes the exit status of that subshell. If that function
      is not defined, the shell prints an error message and returns an exit status of 127.


      If the search is successful, or if the command name contains one or more slashes, the shell  exe‐
検索に成功した場合、またはコマンド名に1つ以上のスラッシュが含まれている場合、シェルは指定されたプログラムを別の実行環境で実行する。 引数0は与えられた名前に設定され、コマンドの残りの引数は、もしあれば与えられた引数に設定される。
      cutes  the  named  program  in  a  separate execution environment.  Argument 0 is set to the name
      given, and the remaining arguments to the command are set to the arguments given, if any.


      If this execution fails because the file is not in executable format, and the file is not  a  di‐
ファイルが実行可能形式でなく、ファイルがディレクトリでないためにこの実行が失敗した場合、それはシェルスクリプト(シェルコマンドを含むファイル)であると仮定される。 それを実行するためにサブシェルが生成される。 このサブシェルは自分自身を再初期化するので、あたかも新しいシェルがスクリプトを処理するために呼び出されたかのような効果が得られるが、例外として、親が記憶しているコマンドの位置(後述の[[#SHELL BUILTIN COMMANDS|SHELL BUILTIN COMMANDS ]]のハッシュを参照)は子シェルに保持される。
      rectory,  it  is  assumed  to be a shell script, a file containing shell commands.  A subshell is
      spawned to execute it.  This subshell reinitializes itself, so that the effect is  as  if  a  new
      shell  had  been  invoked to handle the script, with the exception that the locations of commands
      remembered by the parent (see hash below under SHELL BUILTIN COMMANDS) are retained by the child.


      If the program is a file beginning with #!, the remainder of the first line specifies  an  inter‐
プログラムが<nowiki>#!</nowiki>で始まるファイルである場合、最初の行の残りはプログラムのインタープリタを指定する。 シェルは、この実行形式を扱わないオペレーティングシステム上で、指定されたインタプリタを実行する。 インタプリタへの引数は、プログラムの1行目のインタプリタ名に続く1つのオプション引数、プログラム名、コマンド引数(もしあれば)の順で構成される。
      preter  for  the program.  The shell executes the specified interpreter on operating systems that
      do not handle this executable format themselves.  The arguments to the interpreter consist  of  a
      single  optional  argument  following the interpreter name on the first line of the program, fol‐
      lowed by the name of the program, followed by the command arguments, if any.


== COMMAND EXECUTION ENVIRONMENT ==
== COMMAND EXECUTION ENVIRONMENT ==