/usr/bin/bash: Difference between revisions

Line 1,834: Line 1,834:


== HISTORY EXPANSION ==
== HISTORY EXPANSION ==
The shell supports a history expansion feature that is similar to the history expansion  in  csh.
シェルは、cshのヒストリ展開に似たヒストリ展開機能をサポートしている。
This  section  describes  what syntax features are available.  This feature is enabled by default for interactive shells, and can be disabled using the +H option to the set builtin  command  (see SHELL  BUILTIN COMMANDS  below).  Non-interactive shells do not perform history expansion by default.
このセクションでは、どのような構文機能が利用できるかを説明する。 この機能は対話型シェルではデフォルトで有効になっており、set builtin コマンドの +H オプションを使用して無効にすることができる(後述の「SHELL BUILTIN COMMANDS」を参照)。 非対話型シェルは、デフォルトではヒストリ展開を行わない。


History expansions introduce words from the history list into the input stream, making it easy to repeat  commands,  insert the arguments to a previous command into the current input line, or fix errors in previous commands quickly.
ヒストリ拡張は、ヒストリリストから単語を入力ストリームに導入し、コマンドを繰り返したり、前のコマンドの引数を現在の入力行に挿入したり、前のコマンドのエラーを素早く修正したりすることを容易にする。


History expansion is performed immediately after a complete line is read, before the shell breaks it  into  words,  and  is  performed on each line individually without taking quoting on previous lines into account.  It takes place in two parts.  The first is to determine which line from  the history  list  to use during substitution.  The second is to select portions of that line for inclusion into the current one.  The line selected from the history is the event, and the  portions of  that  line  that are acted upon are words.  Various modifiers are available to manipulate the selected words.  The line is broken into words in the same fashion as when reading input, so that several  metacharacter-separated words surrounded by quotes are considered one word.  History expansions are introduced by the appearance of the history expansion character, which is ! by  default.   Only  backslash (\) and single quotes can quote the history expansion character, but the history expansion character is also treated as quoted if it immediately precedes the closing double quote in a double-quoted string.
ヒストリ展開は、完全な行が読み込まれた直後、シェルがそれを単語に分割する前に実行され、前の行のクォートを考慮することなく、各行に対して個別に実行される。 これは2つの部分に分かれて行われる。 1つ目は、置換時に履歴リストからどの行を使用するかを決定することである。 もうひとつは、その行の一部を現在の行に含めるために選択することである。 履歴から選択された行がイベントであり、その行の一部が単語となる。 選択された単語を操作するために、さまざまな修飾子が利用できる。 行は入力を読むときと同じ方法で単語に分割され、引用符で囲まれたメタ文字で区切られた複数の単語は1つの単語とみなされる。 ヒストリ拡張は、ヒストリ拡張文字(デフォルトではヒストリ展開文字を引用符で囲むことができるのは、バックスラッシュ( \ )と一重引用符だけであるが、二重引用符で囲んだ文字列の閉じ二重引用符の直前にヒストリ展開文字がある場合も、引用符で囲んだものとして扱われる。


Several characters inhibit history expansion if found immediately following the history expansion character, even if it is unquoted: space, tab, newline, carriage return, and =.  If  the  extglob shell option is enabled, ( will also inhibit expansion.
extglobシェル・オプションが有効な場合、()も展開を抑制する。


Several  shell options settable with the shopt builtin may be used to tailor the behavior of history expansion.  If the histverify shell option is enabled (see the  description  of  the  shopt builtin  below),  and readline is being used, history substitutions are not immediately passed to the shell parser.  Instead, the expanded line is reloaded into the readline  editing  buffer  for further  modification.  If readline is being used, and the histreedit shell option is enabled, a failed history substitution will be reloaded into the readline  editing  buffer  for  correction.
shopt 組み込み関数で設定可能ないくつかのシェル・オプションを使用して、ヒストリ展開の動作を調整することができる。 histverify シェル・オプションが有効で(後述の [[#SHELL BUILTIN COMMANDS|SHELL BUILTIN COMMANDS ]]の説明を参照)、readline が使用されている場合、ヒストリ置換はシェル・パーサにすぐには渡されない。 その代わりに、展開された行はreadline編集バッファに再ロードされ、さらに修正される。 readlineが使用されていて、histreeditシェルオプションが有効になっている場合、失敗したヒストリ置換は修正のためにreadline編集バッファにリロードされる。
The  -p option to the history builtin command may be used to see what a history expansion will do before using it.  The -s option to the history builtin may be used to add commands to the end  of the  history  list without actually executing them, so that they are available for subsequent recall.
history 組み込みコマンドの -p オプションを使用すると、ヒストリ拡張を使用する前に、その拡張が何をするかを確認することができる。 history組み込みコマンドの-sオプションは、コマンドを実際に実行することなく、履歴リストの最後に追加するために使用される。


The shell allows control of the various characters used by the history expansion  mechanism  (see the  description  of  histchars above under Shell Variables).  The shell uses the history comment character to mark history timestamps when writing the history file.
シェルでは、ヒストリ展開メカニズムで使用されるさまざまな文字を制御できる(上記の「[[#Shell Variables|Shell Variables ]]」の「histchars」の説明を参照のこと)。 シェルはヒストリファイルを書き込む際に、ヒストリのタイムスタンプをマークするためにヒストリコメント文字を使用する。


=== Event Designators ===
=== Event Designators ===