/usr/bin/bash: Difference between revisions

Line 317: Line 317:


=== Special Parameters ===
=== Special Parameters ===
      The shell treats several parameters specially.  These parameters may only be referenced; assign‐
シェルはいくつかのパラメータを特別に扱う。 これらのパラメータは参照のみ可能で、代入はできない。
      ment to them is not allowed.
;*       
      *      Expands to the positional parameters, starting from one.  When the expansion is not within
:1 から始まる位置パラメーターに展開する。 展開が二重引用符で囲まれていない場合、各位置パラメーターは別々の単語に展開される。 それが実行されるコンテキストでは、それらの単語はさらに単語分割とパス名展開の対象となる。展開が二重引用符で囲まれている場合は、各パラメータの値がIFS特殊変数の最初の文字で区切られた1つの単語に展開される。 つまり、"$*""$1c$2c... "と等価であり、cはIFS変数の値の最初の文字である。 IFSが未設定の場合、パラメータは空白で区切られる。 IFSがNULLの場合、パラメータは区切り文字なしで結合される。
              double quotes, each positional parameter expands to a separate word.  In contexts where it
;@       
              is  performed,  those  words are subject to further word splitting and pathname expansion.
:1 から始まる位置パラメーターに展開される。 単語分割が行われるコンテキストでは、各位置パラメーターを別々の単語に展開する。 単語分割が行われないコンテキストでは、各位置パラメーターをスペースで区切った 単語に展開する。 展開が二重引用符で囲まれている場合、各パラメーターは別々の単語に展開される。 つまり、"$@""$1" "$2"...と等価である。 二重引用符による展開が単語内で起こる場合、最初のパラメータの展開は元の単語の先頭部分と結合され、最後のパラメータの展開は元の単語の最後の部分と結合される。 位置パラメーターがない場合、"$@"と"$@"は何も展開されない(つまり削除される)。
              When the expansion occurs within double quotes, it expands to a single word with the value
;#       
              of  each parameter separated by the first character of the IFS special variable.  That is,
:位置パラメーターの数を10進数で表す。
              "$*" is equivalent to "$1c$2c...", where c is the first character of the value of the IFS
;?       
              variable.  If  IFS is unset, the parameters are separated by spaces.  If IFS is null, the
:最後に実行されたフォアグラウンド・パイプラインの終了ステータスに展開される。
              parameters are joined without intervening separators.
;-       
      @      Expands to the positional parameters, starting from one.  In contexts where word splitting
:set 組み込みコマンド、またはシェル自身が設定したオプションフラグ(-i オプションなど)に展開される。
              is  performed,  this  expands  each positional parameter to a separate word; if not within
;$       
              double quotes, these words are subject to word splitting.  In contexts where  word  split‐
:シェルのプロセス ID に展開する。 () サブシェルでは、サブシェルではなく現在のシェルのプロセス ID に展開される。
              ting  is not performed, this expands to a single word with each positional parameter sepa‐
;!       
              rated by a space.  When the expansion occurs within double quotes, each parameter  expands
:非同期コマンドとして実行されたか、bg組み込み関数(以下のJOB制御を参照)を使用して実行されたかにかかわらず、直近にバックグラウンドに配置されたジョブのプロセスIDに展開される。
              to  a  separate  word.  That is, "$@" is equivalent to "$1" "$2" ... If the double-quoted
;0       
              expansion occurs within a word, the expansion of the first parameter is  joined  with  the
:シェルまたはシェルスクリプトの名前に展開される。 これはシェル初期化時に設定される。コマンドファイルを指定してbashを起動すると、$0にそのファイル名が設定される。 bashが-cオプション付きで起動された場合、$0は、実行する文字列があれば、その文字列の後の最初の引数に設定される。 そうでない場合は、引数0で指定された、bashの起動に使用されたファイル名が設定される。
              beginning  part  of  the  original word, and the expansion of the last parameter is joined
              with the last part of the original word.  When there are no  positional  parameters,  "$@"
              and $@ expand to nothing (i.e., they are removed).
      #      Expands to the number of positional parameters in decimal.
      ?      Expands to the exit status of the most recently executed foreground pipeline.
      -      Expands  to the current option flags as specified upon invocation, by the set builtin com‐
              mand, or those set by the shell itself (such as the -i option).
      $      Expands to the process ID of the shell.  In a () subshell, it expands to the process ID of
              the current shell, not the subshell.
      !      Expands to the process ID of the job most recently placed into the background, whether ex‐
              ecuted as an asynchronous command or using the bg builtin (see JOB CONTROL below).
      0      Expands to the name of the shell or shell script.  This is set  at  shell  initialization.
              If  bash  is invoked with a file of commands, $0 is set to the name of that file.  If bash
              is started with the -c option, then $0 is set to the first argument after the string to be
              executed, if one is present.  Otherwise, it is set to the filename used to invoke bash, as
              given by argument zero.


=== Shell Variables ===
=== Shell Variables ===