展示 bash shell stdout/stderr 重定向行为的备忘单
是否有一个很好的备忘单展示了 BASH shell 重定向的多种用途?我很想把这样的东西送给我的学生。我希望看到一些示例:(
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 #print stdout,stderr to screen while writing to result.txt
或者我们可以将其设为社区维基并在此列举此类内容)
谢谢!
设置跳转
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 #print 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
http://wiki.linuxquestions.org/wiki/Bash-operators
http://wiki.linuxquestions.org/wiki/Bash-operators
Peteris Krumins 还有一个相当全面的备忘单:http://www.catonmat。网/博客/bash-redirections-cheat-sheet/
Peteris Krumins also has a pretty comprehensive cheat sheet: http://www.catonmat.net/blog/bash-redirections-cheat-sheet/
您还可以查看高级 Bash 指南
you can also look at Advanced Bash Guide
http://tldp.org/LDP/abs/html/process-sub。 html
您的学生可能也会喜欢一些流程替换。它与IO重定向密切相关。
编辑:看起来丹尼斯·威廉姆森的链接已经讨论了流程替换:)
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 :)