/usr/bin/bash: Difference between revisions

Line 1,824: Line 1,824:


== HISTORY ==
== HISTORY ==
When the -o history option to the set builtin is enabled, the shell provides access to  the  command  history, the list of commands previously typed.  The value of the HISTSIZE variable is used as the number of commands to save in a history list.  The text of the last HISTSIZE commands (default  500)  is  saved.  The shell stores each command in the history list prior to parameter and variable expansion (see EXPANSION above) but after history expansion is performed, subject to the values of the shell variables HISTIGNORE and HISTCONTROL.
set 組み込み関数の -o history オプションを有効にすると、シェルはコマンド履歴(以前に入力したコマンドのリスト)にアクセスできるようになる。 '''HISTSIZE''' 変数の値は、履歴リストに保存するコマンドの数として使用される。 最後のHISTSIZEコマンド(デフォルト500)のテキストが保存される。 シェルは、パラメータと変数の拡張(上記のEXPANSIONを参照)の前に、ヒストリ拡張が実行された後に、シェル変数'''HISTIGNORE'''と'''HISTCONTROL'''の値に従って、各コマンドをヒストリリストに保存する。


On  startup,  the  history  is  initialized from the file named by the variable HISTFILE (default ~/.bash_history).  The file named by the value of HISTFILE is truncated, if necessary, to contain no  more than the number of lines specified by the value of HISTFILESIZE.  If HISTFILESIZE is unset, or set to null, a non-numeric value, or a numeric value less than zero, the history file  is not truncated.  When the history file is read, lines beginning with the history comment character followed immediately by a digit are interpreted as timestamps for  the  following  history  line. These  timestamps are optionally displayed depending on the value of the HISTTIMEFORMAT variable.
起動時に、履歴は変数'''HISTFILE'''で指定されたファイル(デフォルトは~/.bash_history)から初期化される。 '''HISTFILE'''の値で指定されたファイルは、必要に応じて'''HISTFILESIZE'''の値で指定された行数以下に切り詰められる。 '''HISTFILESIZE'''が未設定、またはNULL、非数値、0未満の数値に設定されている場合、 履歴ファイルは切り捨てられない。 ヒストリファイルが読み込まれると、ヒストリコメント文字の直後に数字が続く行は、次のヒストリ行のタイムスタンプとして解釈される。これらのタイムスタンプは、変数'''HISTTIMEFORMAT'''の値に応じてオプションで表示される。
When a shell with history enabled exits, the last $HISTSIZE lines are  copied  from  the  history list to $HISTFILE.  If the histappend shell option is enabled (see the description of shopt under SHELL BUILTIN COMMANDS below), the lines are appended to the history file, otherwise the  history file  is overwritten.  If HISTFILE is unset, or if the history file is unwritable, the history is not saved. If the HISTTIMEFORMAT variable is set, time stamps are written to the  history  file, marked  with the history comment character, so they may be preserved across shell sessions.  This uses the history comment character to distinguish timestamps from  other  history  lines.  After saving the history, the history file is truncated to contain no more than HISTFILESIZE lines.  If HISTFILESIZE is unset, or set to null, a non-numeric value, or a numeric value  less  than  zero, the history file is not truncated.
履歴を有効にしたシェルが終了すると、最後の $HISTSIZE 行が履歴リストから $HISTFILE にコピーされる。 histappend シェル・オプションが有効な場合 (以下の [[#SHELL BUILTIN COMMANDS|SHELL BUILTIN COMMANDS ]] の shopt の説明を参照のこと)、その行はヒストリ・ファイルに追加される。 HISTFILEが設定されていない場合、または履歴ファイルが書き込み不可能な場合、履歴は保存されない。 '''HISTTIMEFORMA'''T変数が設定されている場合、履歴ファイルにタイムスタンプが書き込まれ、履歴コメント文字でマークされる。 これは、タイムスタンプを他のヒストリ行と区別するためにヒストリコメント文字を使用する。 ヒストリを保存した後、ヒストリファイルは'''HISTFILESIZE'''行以下に切り詰められる。 '''HISTFILESIZE'''が設定されていないか、NULL、数値以外、または0未満の数値に設定されている場合、ヒストリファイルは切り捨てられない。


The builtin command fc (see SHELL BUILTIN COMMANDS below) may be used to list or edit and re-execute a portion of the history list.  The history builtin may be used to  display  or  modify  the history  list  and manipulate the history file.  When using command-line editing, search commands are available in each editing mode that provide access to the history list.
組み込みコマンドfc(後述の「[[#SHELL BUILTIN COMMANDS|SHELL BUILTIN COMMANDS ]]」を参照)を使用して、ヒストリリストの一部を一覧表示または編集して再実行することができる。 history組み込みコマンドは、履歴リストの表示や変更、履歴ファイルの操作に使用できる。 コマンドライン編集を使用する場合、各編集モードで履歴リストにアクセスできる検索コマンドが利用できる。
The shell allows control over which commands are saved on the history list.  The HISTCONTROL and HISTIGNORE variables may be set to cause the shell to save only a subset of the commands entered.
シェルでは、どのコマンドを履歴リストに保存するかを制御できる。 '''HISTCONTROL''' 変数と HISTIGNORE 変数を設定することで、入力されたコマンドの一部だけをシェルに保存させることができる。
The cmdhist shell option, if enabled, causes the shell to attempt to save each line of  a  multiline  command  in the same history entry, adding semicolons where necessary to preserve syntactic correctness.  The lithist shell option causes the shell to save the command  with  embedded  newlines  instead of semicolons.  See the description of the shopt builtin below under SHELL BUILTIN COMMANDS for information on setting and unsetting shell options.
cmdhist シェル・オプションを有効にすると、シェルは複数行のコマンドの各行を同じ履歴エントリに保存しようとし、構文の正しさを保つために必要な場合はセミコロンを追加する。 lithist シェル・オプションは、セミコロンの代わりに改行を埋め込んでコマンドを保存するようにする。 シェル・オプションの設定と解除については、後述の「[[#SHELL BUILTIN COMMANDS|SHELL BUILTIN COMMANDS ]]」の shopt 組み込みコマンドの説明を参照のこと。


== HISTORY EXPANSION ==
== HISTORY EXPANSION ==