【问题标题】:Shortening Bash output command缩短 Bash 输出命令
【发布时间】:2010-12-19 10:20:28
【问题描述】:

有没有比这更有效的命令输出方式:

whereis python > test.txt;date >> test.txt;who >> test.txt

【问题讨论】:

    标签: bash shell terminal


    【解决方案1】:

    怎么样:

    { whereis python; date; who; } > test.txt
    

    编辑:

    {...} 表示法指示bash 在当前 shell 中启动这些命令,而不是像使用 (...) 表示法时那样使用子 shell。由于避免创建新流程,因此效率稍高。

    如果您想临时更改命令的环境(工作目录、变量等),(...) 表示法更易于使用,因为您不必事后手动恢复所有更改:

    ( whereis python; date; who ) > test.txt
    

    【讨论】:

      【解决方案2】:
      (whereis python; date; who) >test.txt
      

      【讨论】:

        猜你喜欢
        • 2019-07-18
        • 1970-01-01
        • 1970-01-01
        • 2021-01-14
        • 2020-11-15
        • 2015-09-18
        • 1970-01-01
        • 2015-06-24
        • 2020-03-18
        相关资源
        最近更新 更多