/usr/bin/bash: Difference between revisions

Line 1,168: Line 1,168:


== COMMAND EXECUTION ENVIRONMENT ==
== COMMAND EXECUTION ENVIRONMENT ==
      The shell has an execution environment, which consists of the following:
シェルは以下の実行環境を持つ:


      •      open files inherited by the shell at invocation, as modified by redirections  supplied  to
* 起動時にシェルに継承されるオープンファイル、および exec 組み込み関数に供給されるリダイレクションによって変更されるオープンファイル。
              the exec builtin
* cd、pushd、または popd によって設定されるか、起動時にシェルによって継承されるカレント作業ディレクトリ。
umaskによって設定されるか、シェルの親から継承されるファイル作成モードマスク
* trapによって設定される現在のトラップ
* 変数代入またはsetで設定された、またはシェルの親から継承された 環境中のシェルパラメータ
* 実行中に定義された、またはシェル親環境から継承されたシェル関数
* (デフォルトまたはコマンドライン引数で)起動時に有効化されるオプション、 または set で有効化されるオプション。
* shoptで有効になるオプション
* aliasで定義されたシェルのエイリアス
* バックグラウンド・ジョブ、$$の値、PPIDの値を含む様々なプロセスID


      •      the current  working directory as set by cd, pushd, or popd, or inherited by the shell at
組み込み関数やシェル関数以外の単純なコマンドを実行する場合、そのコマンドは、以下から構成 される別の実行環境で起動される。 特に断りのない限り、値はシェルから継承される。
              invocation


      •      the file creation mode mask as set by umask or inherited from the shell's parent
* シェルの開いているファイルと、コマンドへのリダイレクトによって指定された変更と追加。
* 現在の作業ディレクトリ
* ファイル作成モードのマスク
* コマンド用にエクスポートされた変数と一緒に、エクスポート用にマークされたシェル変数と関数が環境で渡される。
* シェルによって捕捉されたトラップは、シェルの親から継承された値にリセットされ、シェルによって無視されたトラップは無視される。


      •      current traps set by trap
この別の環境で起動されたコマンドは、シェルの実行環境に影響を与えることはできない。


      •      shell parameters that are set by variable assignment or with set  or  inherited  from  the
コマンド置換、括弧でグループ化されたコマンド、および非同期コマンドは、シェルによって捕捉されたトラップが、シェルが起動時に親から継承した値にリセットされることを除いて、シェル環境の複製であるサブシェル環境で起動される。
              shell's parent in the environment
パイプラインの一部として呼び出される組み込みコマンドも、サブシェル環境で実行される。 サブシェル環境に加えられた変更は、シェルの実行環境に影響しない。


      •      shell functions defined during execution or inherited from the shell's parent in the envi‐
コマンド置換を実行するために生成されたサブシェルは、親シェルから -e オプションの値を継承する。 posix モードでない場合、bash はそのようなサブシェルで -e オプションをクリアする。
              ronment


      •      options enabled at invocation (either by default or with command-line arguments) or by set
コマンドの後に&が続き、ジョブ制御がアクティブでない場合、コマンドのデフォルト標準入力は空のファイル<u>/dev/null</u>になる。 それ以外の場合、呼び出されたコマンドは、リダイレクトによって変更された呼び出し元のシェルのファイル記述子を継承する。
 
      •      options enabled by shopt
 
      •      shell aliases defined with alias
 
      •      various process IDs, including those of background jobs, the value of $$, and the value of
              PPID
 
      When  a simple command other than a builtin or shell function is to be executed, it is invoked in
      a separate execution environment that consists of the following.  Unless  otherwise  noted,  the
      values are inherited from the shell.
 
      •      the  shell's open files, plus any modifications and additions specified by redirections to
              the command
 
      •      the current working directory
 
      •      the file creation mode mask
 
      •      shell variables and functions marked for export, along with  variables  exported  for  the
              command, passed in the environment
 
      •      traps  caught  by the shell are reset to the values inherited from the shell's parent, and
              traps ignored by the shell are ignored
 
      A command invoked in this separate environment cannot affect the shell's execution environment.
 
      Command substitution, commands grouped with parentheses, and asynchronous commands are invoked in
      a  subshell environment that is a duplicate of the shell environment, except that traps caught by
      the shell are reset to the values that  the  shell  inherited  from  its  parent  at  invocation.
      Builtin  commands that are invoked as part of a pipeline are also executed in a subshell environ‐
      ment.  Changes made to the subshell environment cannot affect the shell's execution environment.
 
      Subshells spawned to execute command substitutions inherit the value of the -e  option  from  the
      parent shell.  When not in posix mode, bash clears the -e option in such subshells.
 
      If a command is followed by a & and job control is not active, the default standard input for the
      command is the empty file /dev/null.  Otherwise, the invoked command inherits the  file  descrip‐
      tors of the calling shell as modified by redirections.


== ENVIRONMENT ==
== ENVIRONMENT ==