/usr/bin/bash: Difference between revisions

No edit summary
Line 296: Line 296:


== PARAMETERS ==
== PARAMETERS ==
      A parameter is an entity that stores values.  It can be a name, a number, or one of  the  special
パラメータは値を格納するエンティティである。 名前、数字、または以下の「特別なパラメータ」に列挙されている特別な文字のいずれかになる。 変数は、名前で示されるパラメータである。変数は値と0個以上の属性を持つ。 属性は、declare組み込みコマンドを使用して割り当てられる(後述の「[[#SHELL BUILTIN COMMANDS|SHELL BUILTIN COMMANDS ]]」のdeclareを参照)。
      characters  listed  below under Special Parameters.  A variable is a parameter denoted by a name.
      A variable has a value and zero or more attributes.  Attributes are assigned  using  the  declare
      builtin command (see declare below in SHELL BUILTIN COMMANDS).


      A  parameter  is  set if it has been assigned a value.  The null string is a valid value.  Once a
パラメータには値が設定される。 NULL文字列は有効な値である。 一度設定された変数は、unset 組み込みコマンド(後述の [[#SHELL BUILTIN COMMANDS|SHELL BUILTIN COMMANDS ]]を参照)を使用することによってのみ設定解除することができる。
      variable is set, it may be unset only by using the unset builtin command (see SHELL BUILTIN COM‐
      MANDS below).


      A variable may be assigned to by a statement of the form
変数は、次のようなステートメントで代入することができる。


              name=[value]
<code>name=[value]</code>


      If value is not given, the variable is assigned the null string.  All values undergo tilde expan‐
valueが与えられない場合、変数にはヌル文字列が代入される。 すべての値は、チルダ展開、パラメータ展開、変数展開、コマンド置換、算術展開、引用符除去を受ける(下記の[[#EXPANSION|EXPANSION ]]を参照)。 変数に整数属性が設定されている場合、''$((...))''展開が使用されなくても、値は算術式として評価される(下記の算術式展開を参照)。 単語の分割は、後述の「特殊パラメータ」で説明する"$@"を除いて行われない。 パス名展開は行われない。 代入文は、alias、declare、typeset、export、readonly、local組み込みコマンド(宣言コマンド)の引数としても使用できる。 posix モードの場合、これらの組み込み関数は、コマンド組み込み関数の 1 つまたは複数のインスタンスの後にコマンド内に出現し、これらの代入文のプロパティを保持することができる。
      sion, parameter and variable expansion, command substitution, arithmetic expansion, and quote re‐
      moval (see EXPANSION below).  If the variable has its integer attribute set, then value is evalu‐
      ated as an arithmetic expression even if the $((...)) expansion is not used (see  Arithmetic  Ex‐
      pansion below).  Word splitting is not performed, with the exception of "$@" as explained below
      under Special Parameters.  Pathname expansion is not performed.  Assignment statements  may  also
      appear  as arguments to the alias, declare, typeset, export, readonly, and local builtin commands
      (declaration commands).  When in posix mode, these builtins may appear in a command after one  or
      more instances of the command builtin and retain these assignment statement properties.


      In  the  context  where an assignment statement is assigning a value to a shell variable or array
代入文がシェル変数または配列インデックスに値を代入する場合、+= 演算子を使用して変数の前の値に追加または加算することができる。 これには、代入文を受け付けるdeclareなどの組み込みコマンド(宣言コマンド)の引数も含まれる。 整数属性が設定されている変数に+=を適用すると、値は算術式として評価され、変数の現在値に加算される。 複合代入を使用して配列変数に+=を適用すると(後述の「配列」を参照)、変数の値は(=を使用したときのように)設定解除されず、新しい値が配列の最大添字(添字付き配列の場合)より1つ大きい添字から始まる配列に追加されるか、連想配列のキーと値のペアとして追加される。 文字列値の変数に適用すると、valueが展開され、変数の値に追加される。
      index, the += operator can be used to append to or add to the variable's  previous  value.  This
      includes  arguments to builtin commands such as declare that accept assignment statements (decla‐
      ration commands). When += is applied to a variable for which the integer attribute has been set,
      value  is  evaluated as an arithmetic expression and added to the variable's current value, which
      is also evaluated.  When += is applied to an array variable using compound assignment (see Arrays
      below), the variable's value is not unset (as it is when using =), and new values are appended to
      the array beginning at one greater than the array's maximum index (for indexed arrays)  or  added
      as additional key-value pairs in an associative array.  When applied to a string-valued variable,
      value is expanded and appended to the variable's value.


      A variable can be assigned the nameref attribute using the -n option  to  the  declare  or local
declareまたはlocal組み込みコマンド(以下のdeclareとlocalの説明を参照)の-nオプションを使って変数にnameref属性を割り当てると、nameref、つまり別の変数への参照を作成することができる。 これにより、変数を間接的に操作することができる。 nameref変数の参照、代入、解除、属性の変更(nameref属性そのものの使用や変更を除く)は常に、nameref変数の値で指定された変数に対して実行される。 namerefはシェル関数の中で、関数の引数として渡される変数名を参照するためによく使われる。 例えば、シェル関数の最初の引数として変数名が渡された場合、関数内で declare -n ref=$1 を実行すると、最初の引数として渡された変数名を値とする nameref 変数 ref が作成される。 refへの参照や代入、属性の変更は、$1として渡された変数名への参照や代入、属性の変更として扱われる。
      builtin commands (see the descriptions of declare and local below) to create a nameref, or a ref‐
forループの制御変数がnameref属性を持つ場合、単語のリストはシェル変数のリストとすることができ、ループが実行されると、リスト内の各単語に対して順番に名前参照が確立される。 配列変数にnameref属性を与えることはできない。 しかし、nameref 変数は配列変数や添え字付き配列変数を参照できる。 nameref は、unset 組み込み関数の -n オプションを使ってアンセットできる。 そうでない場合、nameref 変数の名前を引数として unset を実行すると、 nameref 変数によって参照される変数がアンセットされる。
      erence to another variable.  This allows variables to be manipulated  indirectly.  Whenever  the
      nameref  variable  is  referenced, assigned to, unset, or has its attributes modified (other than
      using or changing the nameref attribute itself), the operation is actually performed on the vari‐
      able  specified  by  the nameref variable's value.  A nameref is commonly used within shell func‐
      tions to refer to a variable whose name is passed as an argument to the function.  For  instance,
      if a variable name is passed to a shell function as its first argument, running
              declare -n ref=$1
      inside the function creates a nameref variable ref whose value is the variable name passed as the
      first argument.  References and assignments to ref, and changes to its attributes, are treated as
      references, assignments, and attribute modifications to the variable whose name was passed as $1.
      If the control variable in a for loop has the nameref attribute, the list of words can be a  list
      of  shell variables, and a name reference will be established for each word in the list, in turn,
      when the loop is executed.  Array variables cannot be  given  the nameref attribute.  However,
      nameref variables can reference array variables and subscripted array variables.  Namerefs can be
      unset using the -n option to the unset builtin.  Otherwise, if unset is executed with the name of
      a nameref variable as an argument, the variable referenced by the nameref variable will be unset.


=== Positional Parameters ===
=== Positional Parameters ===