简体   繁体   English

为什么“哪个cp | ls -l“不是”ls -l $(cp)“?

[英]Why “which cp | ls -l ” is not treate as “ls -l $(which cp)”?

According to pipe methodology in Linux, the output of the first command should be treated as input for the second command. 根据Linux中的管道方法,第一个命令的输出应该被视为第二个命令的输入。 So when I am doing which cp | ls -l 所以,当我在做which cp | ls -l which cp | ls -l , it should be treated as ls -l $(which cp) which cp | ls -l ,应该被视为ls -l $(which cp)

But the output is showing something else. 但输出显示其他东西。

Why so ? 为什么这样 ?

ls does not take input from stdin . ls不接受stdin You can work around this if you need to by using xargs : 如果需要使用xargs可以解决此问题:

which cp | xargs ls -l

This will invoke ls -l with the (possibly multiple, if which were to return more than one) filenames as command line arguments, with no standard input. 这将调用ls -l与(可能的多个,如果which是返回多于一个)的文件名作为命令行参数,没有标准输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM