Cheat sheet exhibiting bash shell stdout/stderr redirection behavior
Is there a good cheat sheet demonstrating the many uses of BASH shell redirection? I would love to give such a thing to my students. Some examples I'd like to see covered:
cmd > output_file.txt #redirect stdout to output_file.txt
cmd 2> output_file.txt #redirect stderr to output_file.txt
cmd >& outpout_file.txt #redirect both stderr and stdout to output_file.txt
cmd1 | cmd2 #pipe cmd1 stdout to cmd2's stdin
cmd1 2>&1 | cmd2 #pipe cmd1 stdout and stderr to cmd2's stdin
cmd1 | tee result.txt #print cmd1's stdout to screen and also write to result.txt
cmd1 2>&1 | tee result.txt #prin开发者_开发知识库t stdout,stderr to screen while writing to result.txt
(or we could just make this a community wiki and enumerate such things here)
Thanks!
SetJmp
http://wiki.linuxquestions.org/wiki/Bash-operators
Peteris Krumins also has a pretty comprehensive cheat sheet: http://www.catonmat.net/blog/bash-redirections-cheat-sheet/
you can also look at Advanced Bash Guide
http://tldp.org/LDP/abs/html/process-sub.html
Your students might appreciate a little bit of process substitution as well. It's very closely related to IO redirection.
Edit: It looks like Dennis Williamson's link already talks about process substition :)
精彩评论