我正在尝试使用sh(Bourne Shell)编写一些脚本。我一直遇到这个困惑。针对以下内容:
1. rm `echo test`
2. echo test | rm
我知道反引号可以先运行命令,但是在 #2 的管道输入中,为什么 `rm` 命令没有将 `test` 作为一个参数输入?我是否对管道的理解存在问题?我认为它只是简单地将一个命令的输出作为另一个命令的输入。
还有...可能与我的管道困惑有关。
dir=/blah/blar/blar
files=`ls ${dir} -rt`
count=`wc -l $files` # doesn't work, in fact it's running it along with each file that exists
count2=`$files | wc -l` # doesn't work
为什么我不能将"ls"存储到"files"中并使用它?
wc -l
。 - alex