首页 > 系统服务 > 详细

Shell之StdI/O和Pipe

时间:2019-10-01 16:02:27      阅读:107      评论:0      收藏:0      [点我收藏+]

Shell之StdI/O和Pipe

?? Written by Zak Zhu

学习python风格, 优雅规范书写shell代码

参考

StdI/O重定向

操作 注释
> Overwrite
1> Redirect STDOUT to file
2> Redirect STDERR to file
&> Redirect all output to file
>> Append
1>> Append STDOUT to file
2>> Append STDERR to file
3>> Append all output to file
2>&1 Redirect STDERR to STDOUT
<<WORD Redirect multiple line from keyboard to STDIN with <<WORD

Pipe

  1. COMMAND1 | COMMAND2

    • send STDOUT of COMMAND1 to STDIN of COMMAND2 instead of the screen
    • STDERR is not forwarded across pipes

    技术分享图片

  2. COMMAND1 | tee [-a] FILE | COMMAND2

    stores STDOUT of COMMAND1 in FILE, then pipes to COMMAND2

常用组合

Examples:

  • echo > test

    技术分享图片

  • find /etc/ -name passwd &> find.all

    技术分享图片

  • find /etc/ -name passwd 2>&1 | head

    2>&1: Redirects STDERR to STDOUT

    • Useful for sending all output through a pipe

    技术分享图片

  • (cal 12 2018 ; cal 1 2019) | head -n 12

    技术分享图片

  • find /etc/ -name passwd &> /dev/null

  • find /etc/ -name passwd > find.out 2> find.err

    技术分享图片

  • find /etc/ -name passwd 2> /dev/null | tee find.out | head

    技术分享图片

  • cat > test.sh << EOF

    技术分享图片

Shell之StdI/O和Pipe

原文:https://www.cnblogs.com/zakzhu/p/11615412.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!