問題 coverage-101500-bash-tee-output・第1版

問題

commandの出力をterminalへ表示し、同時に結果fileへも保存する基本のcommandはどれか。

  1. A 

    tee result.txt

  2. B 

    command >result.txtだけ

  3. C 

    xargs result.txt

  4. D 

    cut -d : -f 1

正解:A

理由

teeがstdinをfileとstdoutへ分岐する。

入力と結果

画面とファイルへ同じ2行を出す。

$ printf 'red\nblue\n' | tee copied.txt
red
blue
$ cat copied.txt
red
blue

最初はteeの標準出力、後半は保存したファイルの内容。

選択肢ごとの説明

A.

tee result.txt

fileとstdoutへ出す。

B.

command >result.txtだけ

stdoutをfileへ向け、通常そのままterminalへは出さない。

C.

xargs result.txt

引数の組立てで、出力を二箇所へ複製しない。

D.

cut -d : -f 1

fieldの抽出である。

参考資料

お問い合わせ

演習する →