/usr/bin/dash: Difference between revisions

 
(2 intermediate revisions by the same user not shown)
Line 340: Line 340:


=== Special Parameters ===
=== Special Parameters ===
    A special parameter is a parameter denoted by one of the following special characters.  The value of
特殊パラメータは、以下の特殊文字のいずれかで示されるパラメータである。 パラメータの値は、その文字の横に記載されている。
    the parameter is listed next to its character.


    *            Expands to the positional parameters, starting from one.  When the expansion occurs
;*             
                  within a double-quoted string it expands to a single field with the value of each parame‐
:位置パラメータを1から順に展開する。 展開が二重引用符で囲まれた文字列の中で行われる場合、各パラメータの値が IFS変数の最初の文字で区切られた1つのフィールドに展開され、IFSが設定されていない場合は ⟨スペース⟩で区切られる。
                  ter separated by the first character of the IFS variable, or by a ⟨space⟩ if IFS is un‐
                  set.


    @           Expands to the positional parameters, starting from one.  When the expansion occurs
;@
                  within double-quotes, each positional parameter expands as a separate argument.  If there
:位置パラメータを1から順に展開する。 展開が二重引用符で囲まれている場合、各位置パラメータは別々の引数として展開される。 位置パラメーターがない場合、@が二重引用符で囲まれていても、@の展開は0個の引数を生成する。 これが基本的に意味するのは、例えば$1が "abc "で$2が "def ghi "の場合、"$@"は2つの引数に展開されるということである:
                  are no positional parameters, the expansion of @ generates zero arguments, even when @ is
                  double-quoted.  What this basically means, for example, is if $1 is “abc” and $2 is “def
                  ghi”, then "$@" expands to the two arguments:


                        "abc" "def ghi"
::<nowiki>"abc" "def ghi"</nowiki>


    #           Expands to the number of positional parameters.
;#
:位置パラメーターの数に拡張する。


    ?           Expands to the exit status of the most recent pipeline.
;?
:直近のパイプラインの終了ステータスに展開する。


    - (Hyphen.) Expands to the current option flags (the single-letter option names concatenated into a
;- (Hyphen.)
                  string) as specified on invocation, by the set builtin command, or implicitly by the
:起動時、set 組み込みコマンド、またはシェルによって暗黙的に指定された、現在のオプションフラグ(1文字のオプション名を連結した文字列)に展開する。
                  shell.


    $           Expands to the process ID of the invoked shell.  A subshell retains the same value of $
;$
                  as its parent.
:呼び出されたシェルのプロセス ID に展開される。 サブシェルは、親と同じ $ の値を保持する。


    !           Expands to the process ID of the most recent background command executed from the current
;!
                  shell.  For a pipeline, the process ID is that of the last command in the pipeline.
:現在のシェルから実行された最新のバックグラウンド・コマンドのプロセスIDに展開される。 パイプラインの場合、プロセスIDはパイプラインの最後のコマンドのものになる。


    0 (Zero.)   Expands to the name of the shell or shell script.
;0 (Zero.)
:シェルまたはシェルスクリプトの名前に展開する。


=== Word Expansions ===
=== Word Expansions ===
    This clause describes the various expansions that are performed on words.  Not all expansions are per‐
この節では、単語に対して行われる様々な展開について説明する。 後述するように、すべての展開がすべての単語に対して行われるわけではない。
    formed on every word, as explained later.
後述するように、すべての単語に適用されるわけではない。


    Tilde expansions, parameter expansions, command substitutions, arithmetic expansions, and quote re‐
チルダ展開、パラメータ展開、コマンド置換、算術展開、引用符除去のうち、1つの単語内で行われるものは、1つのフィールドに展開される。 一つの単語から複数のフィールドを作ることができるのは、フィールドの分割かパス名の展開だけである。 このルールの唯一の例外は、上で説明したように、ダブルクォート内での特殊パラメータ@の展開である。
    movals that occur within a single word expand to a single field.  It is only field splitting or path‐
    name expansion that can create multiple fields from a single word.  The single exception to this rule
    is the expansion of the special parameter @ within double-quotes, as was described above.


    The order of word expansion is:
単語展開の順序は以下の通りである:


    1.  Tilde Expansion, Parameter Expansion, Command Substitution, Arithmetic Expansion (these all occur
#チルダ展開、パラメータ展開、コマンド置換、算術展開(これらはすべて同時に行われる)。
          at the same time).
#フィールド分割は、IFS変数がNULLでない限り、ステップ(1)で生成されたフィールドに対して行われる。
#パス名展開(set -fが有効な場合を除く)。
#引用符の除去。


    2.  Field Splitting is performed on fields generated by step (1) unless the IFS variable is null.
文字は、パラメータ展開、コマンド置換、または算術評価の導入に使用される。


    3.  Pathname Expansion (unless set -f is in effect).
チルダ展開(ユーザーのホームディレクトリを置換する)。
 
引用符で囲まれていないチルダ文字(~)で始まる単語は、チルダ展開の対象となる。 スラッシュ(/)または語尾までのすべての文字がユーザー名として扱われ、そのユーザーのホームディレクトリに置き換えられる。 ユーザー名がない場合(~/foobarのように)、チルダはHOME変数の値(現在のユーザーのホームディレクトリ)に置き換えられる。
    4.  Quote Removal.
 
    The $ character is used to introduce parameter expansion, command substitution, or arithmetic evalua‐
    tion.
 
  Tilde Expansion (substituting a user's home directory)
    A word beginning with an unquoted tilde character (~) is subjected to tilde expansion.  All the char‐
    acters up to a slash (/) or the end of the word are treated as a username and are replaced with the
    user's home directory.  If the username is missing (as in ~/foobar), the tilde is replaced with the
    value of the HOME variable (the current user's home directory).


=== Parameter Expansion ===
=== Parameter Expansion ===
Line 417: Line 402:


#パス名展開は展開結果に対して行われない。
#パス名展開は展開結果に対して行われない。
#フィールド分割は、@を除いて、展開結果に対して実行されない。
#フィールド分割は、@を除いて、展開結果に対して実行されない。