缩短Bash输出命令

3
有没有比这更高效的输出命令的方法?
whereis python > test.txt;date >> test.txt;who >> test.txt
2个回答

3
如何呢:
{ whereis python; date; who; } > test.txt

编辑:

{...} 符号指示 bash 在当前 shell 中运行这些命令,而不是使用子 shell,如果使用 (...) 符号的话就会使用子 shell。它稍微更有效率,因为它避免了创建一个新进程。

但是,如果您想临时更改环境(工作目录、变量等)以供命令使用,则使用 (...) 符号更简单,因为您无需手动还原所有更改:

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

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接