|
|
Line 836: |
Line 836: |
|
| |
|
| == REDIRECTION == | | == REDIRECTION == |
| Before a command is executed, its input and output may be redirected using a special notation in‐
| | コマンドが実行される前に、シェルによって解釈される特別な記法を使って、その入出力をリダイレクトすることができる。 リダイレクトによって、コマンドのファイルハンドルを複製したり、開いたり、閉じたり、異なるファイルを参照させたり、コマンドの読み込み先や書き込み先のファイルを変更したりすることができる。 リダイレクションは、現在のシェル実行環境のファイルハンドルを変更するためにも使用できる。 以下のリダイレクション演算子は、単純なコマンドの前でも、コマンドの後でも、どこにでも現れる。 リダイレクションは左から右の順番で処理される。 |
| terpreted by the shell. Redirection allows commands' file handles to be duplicated, opened,
| |
| closed, made to refer to different files, and can change the files the command reads from and
| |
| writes to. Redirection may also be used to modify file handles in the current shell execution
| |
| environment. The following redirection operators may precede or appear anywhere within a simple
| |
| command or may follow a command. Redirections are processed in the order they appear, from left
| |
| to right.
| |
|
| |
|
| Each redirection that may be preceded by a file descriptor number may instead be preceded by a
| | ファイル記述子番号で始まるリダイレクションの前に、<nowiki>{varname}</nowiki>という単語を置くこともできる。 この場合、<nowiki>>&-と<&-</nowiki>を除く各リダイレクト演算子に対して、シェルは10以上のファイル記述子を割り当て、それをvarnameに割り当てる。 もし >&- または <nowiki><&-</nowiki> の前に <nowiki>{varname}</nowiki> があれば、varname の値はクローズするファイル記述子を定義する。 |
| word of the form {varname}. In this case, for each redirection operator except >&- and <&-, the
| | <nowiki>{varname}</nowiki>が与えられると、リダイレクトはコマンドの範囲を超えて持続し、シェルプログラマが自分でファイル記述子を管理できるようになる。 |
| shell will allocate a file descriptor greater than or equal to 10 and assign it to varname. If
| |
| >&- or <&- is preceded by {varname}, the value of varname defines the file descriptor to close.
| |
| If {varname} is supplied, the redirection persists beyond the scope of the command, allowing the
| |
| shell programmer to manage the file descriptor himself.
| |
|
| |
|
| In the following descriptions, if the file descriptor number is omitted, and the first character
| | 以下の記述において、ファイル記述子番号が省略され、リダイレクション演算子の最初の文字が <nowiki><</nowiki> の場合、リダイレクションは標準入力(ファイル記述子0)を参照する。 リダイレクション演算子の最初の文字が<nowiki>></nowiki>の場合、リダイレクションは標準出力(ファイル記述子1)を参照する。 |
| of the redirection operator is <, the redirection refers to the standard input (file descriptor
| |
| 0). If the first character of the redirection operator is >, the redirection refers to the stan‐
| |
| dard output (file descriptor 1).
| |
|
| |
|
| The word following the redirection operator in the following descriptions, unless otherwise
| | 以下の記述でリダイレクション演算子に続く単語は、特に断りのない限り、波括弧展開、チルダ展開、パラメータ展開、変数展開、コマンド置換、算術展開、引用符除去、パス名展開、単語分割の対象となる。 |
| noted, is subjected to brace expansion, tilde expansion, parameter and variable expansion, com‐
| | 複数の単語に展開された場合、bashはエラーを報告する。 |
| mand substitution, arithmetic expansion, quote removal, pathname expansion, and word splitting.
| |
| If it expands to more than one word, bash reports an error.
| |
|
| |
|
| Note that the order of redirections is significant. For example, the command
| | リダイレクトの順番は重要であることに注意。 例えば、コマンド |
|
| |
|
| ls > dirlist 2>&1
| | <code>ls > dirlist 2>&1</code> |
|
| |
|
| directs both standard output and standard error to the file dirlist, while the command
| | は標準出力と標準エラーの両方をファイルdirlistに向ける。 |
|
| |
|
| ls 2>&1 > dirlist
| | <code>ls 2>&1 > dirlist</code> |
|
| |
|
| directs only the standard output to file dirlist, because the standard error was duplicated from
| | なぜなら、標準出力がdirlistにリダイレクトされる前に、標準エラーは標準出力から複製されたからである。 |
| the standard output before the standard output was redirected to dirlist.
| |
|
| |
|
| Bash handles several filenames specially when they are used in redirections, as described in the
| | Bashは、リダイレクトで使用されるいくつかのファイル名を、以下の表で説明するように特別に扱う。 bashが実行されているオペレーティング・システムがこれらの特別なファイルを提供している場合、bashはそれらを使用する。そうでない場合は、以下に説明する動作で内部的にエミュレートする。 |
| following table. If the operating system on which bash is running provides these special files,
| |
| bash will use them; otherwise it will emulate them internally with the behavior described below.
| |
|
| |
|
| /dev/fd/fd
| | :;/dev/fd/fd |
| If fd is a valid integer, file descriptor fd is duplicated.
| | ::fdが有効な整数の場合、ファイル記述子fdは複製される。 |
| /dev/stdin
| | :;/dev/stdin |
| File descriptor 0 is duplicated.
| | ::ファイル記述子 0 が重複している。 |
| /dev/stdout
| | :;/dev/stdout |
| File descriptor 1 is duplicated.
| | ::ファイル記述子 1 が重複している。 |
| /dev/stderr
| | :;/dev/stderr |
| File descriptor 2 is duplicated.
| | ::ファイル記述子 2 が重複している。 |
| /dev/tcp/host/port
| | :;/dev/tcp/host/port |
| If host is a valid hostname or Internet address, and port is an integer port number
| | ::hostに有効なホスト名またはインターネット・アドレスを、portに整数のポート番号またはサービス名を指定すると、bashは対応するTCPソケットを開こうとする。 |
| or service name, bash attempts to open the corresponding TCP socket.
| | :;/dev/udp/host/port |
| /dev/udp/host/port
| | ::hostに有効なホスト名またはインターネット・アドレスを、portに整数のポート番号またはサービス名を指定すると、bashは対応するUDPソケットを開こうとする。 |
| If host is a valid hostname or Internet address, and port is an integer port number
| |
| or service name, bash attempts to open the corresponding UDP socket.
| |
|
| |
|
| A failure to open or create a file causes the redirection to fail.
| | ファイルのオープンまたは作成に失敗すると、リダイレクトは失敗する。 |
|
| |
|
| Redirections using file descriptors greater than 9 should be used with care, as they may conflict
| | シェルが内部的に使用するファイル記述子と衝突する可能性があるため、9 以上のファイル記述子を使用するリダイレクトは注意して使用すべきである。 |
| with file descriptors the shell uses internally.
| |
|
| |
|
| Note that the exec builtin command can make redirections take effect in the current shell.
| | exec組み込みコマンドは、現在のシェルでリダイレクトを有効にすることができることに注意すること。 |
|
| |
|
| === Redirecting Input === | | === Redirecting Input === |