Quantcast
Channel: Bashタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 2881

timeコマンドの結果だけを標準出力に流す。

$
0
0
備忘録 解決策: (time ${some_command} 1>/dev/null 2>&1) 2>&1 例 次のような標準エラーにhello、標準出力にworldを出力するtest.shがあるとき、 test.sh #!/bin/bash echo hello 1>&2 sleep 1 echo world 上記のコマンドラインを実行する。結果をteeコマンドで受けファイルに書き込む。 (time ./test.sh 1>/dev/null 2>&1) 2>&1 | tee result.txt 結果はつぎのようになる。 result.txt real 0m1.423s user 0m0.002s sys 0m0.008s ./test.shの標準出力をNullデバイスにリダイレクトし、エラーを標準出力(つまりNullデバイス)にリダイレクトする。そしてtimeコマンドのエラー出力を標準出力にリダイレクトする。(これはNullデバイスを指さない。かっこの位置に注目。)

Viewing all articles
Browse latest Browse all 2881

Trending Articles