|
|
Line 402: |
Line 402: |
|
| |
|
| === Parameter Expansion === | | === Parameter Expansion === |
| The format for parameter expansion is as follows:
| | パラメータ展開のフォーマットは以下の通りである: |
|
| |
|
| ${expression} | | ${expression} |
|
| |
|
| where expression consists of all characters until the matching “}”. Any “}” escaped by a backslash or
| | 式は、マッチする"}"までのすべての文字で構成される。 バックスラッシュでエスケープされた"}"、または引用符で囲まれた文字列内の"}"、および 埋め込み算術展開、コマンド置換、変数展開の文字は、マッチする"}"を決定する際には検査されない。 |
| within a quoted string, and characters in embedded arithmetic expansions, command substitutions, and
| |
| variable expansions, are not examined in determining the matching “}”.
| |
|
| |
|
| The simplest form for parameter expansion is:
| | パラメータ展開の最も単純な形式は以下のとおりである: |
|
| |
|
| ${parameter} | | ${parameter} |
|
| |
|
| The value, if any, of parameter is substituted.
| | パラメータの値があれば、その値が代入される。 |
|
| |
|
| The parameter name or symbol can be enclosed in braces, which are optional except for positional pa‐
| | パラメータ名または記号は中括弧で囲むことができる。中括弧は、1桁以上の位置パラメー タや、パラメータの後に名前の一部として解釈される文字が続く場合を除き、省略可能である。 パラメータ展開が二重引用符で囲まれている場合、そのパラメータは中括弧で囲むことができる: |
| rameters with more than one digit or when parameter is followed by a character that could be inter‐
| |
| preted as part of the name. If a parameter expansion occurs inside double-quotes:
| |
|
| |
|
| 1. Pathname expansion is not performed on the results of the expansion.
| | #パス名展開は展開結果に対して行われない。 |
|
| |
|
| 2. Field splitting is not performed on the results of the expansion, with the exception of @.
| | #フィールド分割は、@を除いて、展開結果に対して実行されない。 |
|
| |
|
| In addition, a parameter expansion can be modified by using one of the following formats.
| | さらに、以下の書式のいずれかを使用することで、パラメータ展開を変更することができる。 |
|
| |
|
| ${parameter:-word} Use Default Values. If parameter is unset or null, the expansion of word is
| | ;<nowiki>${parameter:-word}</nowiki> |
| substituted; otherwise, the value of parameter is substituted.
| | :デフォルト値を使用する。 パラメータが未設定またはNULLの場合、wordの展開が代入され、そうでない場合、パラメータの値が代入される。 |
|
| |
|
| ${parameter:=word} Assign Default Values. If parameter is unset or null, the expansion of word is
| | ;<nowiki>${parameter:=word}</nowiki> |
| assigned to parameter. In all cases, the final value of parameter is substi‐
| | :デフォルト値を割り当てる。 パラメータが未設定または NULL の場合、単語の展開がパラメータに代入される。 すべての場合において、パラメータの最終値が代入される。 この方法で代入できるのは変数のみで、位置パラメーターや特殊パラメーターは代入できない。 |
| tuted. Only variables, not positional parameters or special parameters, can be
| |
| assigned in this way.
| |
|
| |
|
| ${parameter:?[word]} Indicate Error if Null or Unset. If parameter is unset or null, the expansion
| | ;<nowiki>${parameter:?[word]}</nowiki> |
| of word (or a message indicating it is unset if word is omitted) is written to
| | :Nullまたは未設定の場合、エラーを表示する。 パラメータが未設定またはNULLの場合、wordの展開(wordが省略された場合は未設定であることを示すメッセージ)が標準エラーに書き込まれ、シェルは0以外の終了ステータスで終了する。 そうでなければ、パラメータの値が代入される。 対話型シェルは終了する必要はない。 |
| standard error and the shell exits with a nonzero exit status. Otherwise, the
| |
| value of parameter is substituted. An interactive shell need not exit.
| |
|
| |
|
| ${parameter:+word} Use Alternative Value. If parameter is unset or null, null is substituted; oth‐
| | ;<nowiki>${parameter:+word}</nowiki> |
| erwise, the expansion of word is substituted.
| | :代替値を使用する。 パラメータが未設定またはNULLの場合、NULLが代入され、そうでない場合、単語の展開が代入される。 |
|
| |
|
| In the parameter expansions shown previously, use of the colon in the format results in a test for a
| | :先に示したパラメータ展開では、書式にコロンを使用すると、パラメータが未設定またはNULLであるかどうかをテストすることになる。 |
| parameter that is unset or null; omission of the colon results in a test for a parameter that is only
| |
| unset.
| |
|
| |
|
| ${#parameter} String Length. The length in characters of the value of parameter.
| | ;<nowiki>${#parameter}</nowiki> |
| | :文字列の長さ。 パラメータ値の文字数。 |
|
| |
|
| The following four varieties of parameter expansion provide for substring processing. In each case,
| | 以下の4種類のパラメータ拡張は、部分文字列処理を提供する。 いずれの場合も、パターンの評価には正規表現表記ではなく、パターンマッチング表記(シェルパターン参照)が使われる。 パラメータが*または@の場合、展開結果は不定である。 パラメータ展開文字列全体を二重引用符で囲むと、次の4種類のパターン文字は引用符で囲まれないが、中括弧内の文字は引用符で囲まれる。 |
| pattern matching notation (see Shell Patterns), rather than regular expression notation, is used to
| |
| evaluate the patterns. If parameter is * or @, the result of the expansion is unspecified. Enclosing
| |
| the full parameter expansion string in double-quotes does not cause the following four varieties of
| |
| pattern characters to be quoted, whereas quoting characters within the braces has this effect.
| |
|
| |
|
| ${parameter%word} Remove Smallest Suffix Pattern. The word is expanded to produce a pattern. The
| | ;<nowiki>${parameter%word}</nowiki> |
| parameter expansion then results in parameter, with the smallest portion of the
| | :最小接尾辞パターンを取り除く。 単語を展開してパターンを生成する。 パラメータ展開の結果、パターンにマッチする接尾辞の最小部分が削除されたパラメータが得られる。 |
| suffix matched by the pattern deleted.
| |
|
| |
|
| ${parameter%%word} Remove Largest Suffix Pattern. The word is expanded to produce a pattern. The
| | ;<nowiki>${parameter%%word}</nowiki> |
| parameter expansion then results in parameter, with the largest portion of the
| | :最大の接尾辞パターンを取り除く。 単語を展開してパターンを生成する。 そして、パラメータ展開の結果、パターンにマッチする接尾辞の最大部分が削除されたパラメータが生成される。 |
| suffix matched by the pattern deleted.
| |
|
| |
|
| ${parameter#word} Remove Smallest Prefix Pattern. The word is expanded to produce a pattern. The
| | ;<nowiki>${parameter#word}</nowiki> |
| parameter expansion then results in parameter, with the smallest portion of the
| | :最小の接頭辞パターンを取り除く。 単語を展開してパターンを生成する。 パラメータ展開の結果、パターンにマッチする接頭辞の最小部分が削除されたパラメータが得られる。 |
| prefix matched by the pattern deleted.
| |
|
| |
|
| ${parameter##word} Remove Largest Prefix Pattern. The word is expanded to produce a pattern. The
| | ;<nowiki>${parameter##word}</nowiki> |
| parameter expansion then results in parameter, with the largest portion of the
| | :最大の接頭辞パターンを取り除く。 単語を展開してパターンを生成する。 パラメータ展開の結果、パターンにマッチする接頭辞の最大部分が削除されたパラメータが得られる。 |
| prefix matched by the pattern deleted.
| |
|
| |
|
| === Command Substitution === | | === Command Substitution === |