展示 bash shell stdout/stderr 重定向行为的备忘单

发布于 2024-08-28 04:37:04 字数 698 浏览 12 评论 0原文

是否有一个很好的备忘单展示了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

岁吢 2024-09-04 04:37:04

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/

﹉夏雨初晴づ 2024-09-04 04:37:04

您还可以查看高级 Bash 指南

you can also look at Advanced Bash Guide

影子的影子 2024-09-04 04:37:04

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 :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文