Skip to content

Instantly share code, notes, and snippets.

@okisanjp
Last active December 22, 2016 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save okisanjp/58a68d0101d723b9a787 to your computer and use it in GitHub Desktop.
Save okisanjp/58a68d0101d723b9a787 to your computer and use it in GitHub Desktop.
bash:標準出力も標準エラーもログに出力 ref: http://qiita.com/okisanjp/items/4bdf009176ecae312f84
#!/bin/sh
echo "foo"
cat ./sonna_file_naiyo.txt
echo "bar"
$ sh ./test.sh | tee test.log
foo
cat: ./sonna_file_naiyo.txt: No such file or directory
bar
$ cat ./test.log
foo
bar
$ sh ./test.sh 2>&1 | tee test.log
foo
cat: ./sonna_file_naiyo.txt: No such file or directory
bar
$ cat ./test.log
foo
cat: ./sonna_file_naiyo.txt: No such file or directory
bar
$ sh ./test.sh > test.log 2>&1
$ cat test.log
foo
cat: ./sonna_file_naiyo.txt: No such file or directory
bar
$ sh ./test.sh | tee test.log 2>&1
foo
cat: ./sonna_file_naiyo.txt: No such file or directory
bar
$ cat test.log
foo
bar
$ sh ./test.sh 2>&1 > test.log
cat: ./sonna_file_naiyo.txt: No such file or directory
$ cat test.log
foo
bar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment