doc: More on command substitution
@@ -392,13 +392,18 @@ | ||
392 | 392 | parsed. |
393 | 393 | |
394 | 394 | If command substitution is of the form +`{{commands}}`+, |
395 | -the {{commands}} are not parsed when the command substitution is parsed. | |
395 | +the {{commands}} are not parsed when the command substitution is parsed; | |
396 | +the {{commands}} are parsed each time the command substitution is expanded. | |
396 | 397 | The end of {{commands}} is detected by the first backquote character (+`+) |
397 | 398 | after the beginning of {{commands}} that is not |
398 | 399 | link:syntax.html#quotes[quoted] by a backslash. |
399 | 400 | Backquotes that are part of {{commands}} (typically used for nested command |
400 | 401 | substitution) must be quoted by backslashes. |
401 | -The {{commands}} are parsed each time the command substitution is expanded. | |
402 | +In {{commands}}, backslashes are treated as quotes only when preceding a | |
403 | +dollar (+$+), backquote, newline, or another backslash. Additionally, if the | |
404 | +command substitution occurs inside double quotes, double quotes in | |
405 | +{{commands}} must be quoted with a backslash. Those backslashes are removed | |
406 | +before {{commands}} are parsed. | |
402 | 407 | |
403 | 408 | [[arith]] |
404 | 409 | == Arithmetic expansion |
@@ -228,7 +228,7 @@ | ||
228 | 228 | |
229 | 229 | +$(+ と +)+ で囲んだコマンド置換の{{コマンド}}は、コマンド置換の入れ子やリダイレクトなどを考慮して予め解析されます。従って、+$(+ と +)+ の間には基本的に通常通りコマンドを書くことができます。ただし、<<arith,数式展開>>との混同を避けるため、中の{{コマンド}}が +(+ で始まる場合は{{コマンド}}の最初に空白を挿し挟んでください。 |
230 | 230 | |
231 | -+`+ で囲むコマンド置換では、コマンド置換の入れ子などは考慮せずに、{{コマンド}}の中に最初に (バックスラッシュでlink:syntax.html#quotes[クォート]していない) +`+ が現れたところでコマンド置換の終わりとみなされます。+`+ で囲んだコマンド置換の中に +`+ で囲んだコマンド置換を書く場合は、内側の +`+ をバックスラッシュでクォートする必要があります。その他、{{コマンド}}の一部として +`+ を入れたいときは、(それが{{コマンド}}内部で一重または二重引用符でクォートされていても) バックスラッシュでクォートする必要があります。 | |
231 | ++`+ で囲むコマンド置換では、コマンド置換の入れ子などは考慮せずに、{{コマンド}}の中に最初に (バックスラッシュでlink:syntax.html#quotes[クォート]していない) +`+ が現れたところでコマンド置換の終わりとみなされます。+`+ で囲んだコマンド置換の中に +`+ で囲んだコマンド置換を書く場合は、内側の +`+ をバックスラッシュでクォートする必要があります。その他、{{コマンド}}の一部として +`+ を入れたいときは、(それが{{コマンド}}内部で一重または二重引用符でクォートされていても) バックスラッシュでクォートする必要があります。{{コマンド}}の中ではバックスラッシュは ++$++・++`++・バックスラッシュ・改行の直前にある場合のみ引用符として扱われます。また、++`++ で囲んだコマンド置換が二重引用符の中で使われる場合は、{{コマンド}}の中に現れる二重引用符もバックスラッシュでクォートする必要があります。これらのバックスラッシュは{{コマンド}}が解析される前に削除されます。 | |
232 | 232 | |
233 | 233 | +$(+ と +)+ で囲んだコマンド置換の中のコマンドは、そのコマンド置換を含むコマンドを解析する時に一緒に解析されます (link:posix.html[POSIX 準拠モード]を除く)。+`+ で囲んだコマンド置換の中のコマンドは、POSIX 準拠モードであるかどうかに関わらず、そのコマンド置換が実行される時に毎回解析されます。 |
234 | 234 |