bashのファイルディスクリプタ演算子
シェルとファイルデスクリプタのお話にも解説はあるが、基本は bash(1) が全て。
ファイルディスクリプタの管理
Section titled “ファイルディスクリプタの管理”/dev/fd に開いているファイルディスクリプタがリストされている。
ls /dev/fdリダイレクト
Section titled “リダイレクト”[cmd] &>file or [cmd] >&file
Section titled “[cmd] &>file or [cmd] >&file”>file 2>&1 と同じ。&> の方が好ましい。
[cmd] &>>file or [cmd] >>&file
Section titled “[cmd] &>>file or [cmd] >>&file”>>file 2>&1 と同じ。&>> の方が好ましい。
[cmd1] |& [cmd2]
Section titled “[cmd1] |& [cmd2]”cmd1 の標準出力とエラー出力を cmd2 にパイプする。
[cmd]<<<string
Section titled “[cmd]<<<string”cmd を実行して標準入力に string を入力する。
ファイル操作
Section titled “ファイル操作”exec [n]<&fd
Section titled “exec [n]<&fd”fd を n に複製(dup2)する。fd が読み込みモードでオープンされていないファイルディスクリプタならエラーになる。また、n を省略すると stdin が使われる。
fd が - の場合は n を close する。
exec [n]>&fd
Section titled “exec [n]>&fd”上とだいたい同じだけど、fd が書き込みモードでない場合はエラーになる。n を省略すると stdout が使われる。
fd が - の場合は n を close する。
exec [n]<&fd-
Section titled “exec [n]<&fd-”<&fd と似ているが、これは fd を複製したあと fd 自体を閉じる。
exec [n]>&fd-
Section titled “exec [n]>&fd-”>&fd と似ているが、これは fd を複製したあと fd 自体を閉じる。
exec [n]<file
Section titled “exec [n]<file”読み込みモードで n をオープンする。n を省略すると stdin が使われる。
exec [n]>file
Section titled “exec [n]>file”書き込みモードで n をオープンする。file がなければ作られ、内容は消える。n を省略すると stdout が使われる。
exec [n]>>file
Section titled “exec [n]>>file”追記モードで n をオープンする。file がなければ作られる。n を省略すると stdout が使われる。
exec [n]<>file
Section titled “exec [n]<>file”読み書きモードで n をオープンする。file がなければ作られる。