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

Har*_*rma 4 linux bash command-line ls pipe

根据Linux中的管道方法,第一个命令的输出应该被视为第二个命令的输入.因此,当我这样做时which cp | ls -l,应将其视为ls -l $(which cp)

但输出显示其他东西.

为什么这样 ?

Joh*_*nck 12

ls不接受输入stdin.如果您需要使用xargs以下方法,可以解决此问题:

which cp | xargs ls -l
Run Code Online (Sandbox Code Playgroud)

这将调用ls -l(可能是多个,如果which要返回多个)文件名作为命令行参数,没有标准输入.