2012-09-18 30 views

回答

3

不要管他们。

而是执行此操作:

cat output.txt ; rm output.txt 
grep -c 'ps' count.tmp ; rm count.tmp 

编辑:管道(|)需要一个命令的标准输出,并运行它进入另一个标准输入...是这样的:

# Get the number of lines 
cat output.txt | wc -l 

or 

echo "Hello there" | tr -d' ' 

要加入命令,请使用;&&

;将运行命令一个压脚提升其他

echo Hi ; false; echo there 

&&才能运行该命令中的零个状态代码(成功)退出下一个命令。

echo Hi && false && echo there 
0

管道输送命令can be run in any order,所以不能保证rm命令将不会被首先运行。使用

cat output.txt && rm output.txt 

如果cat命令成功,这将只删除该文件。

+1

对于来自Windows/DOS背景的人来说,这是一个重要的区别,管道命令* do *按顺序运行,在临时文件中传递stdio。 –

相关问题