Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. So when I am doing which cp | ls -l, it should be treated as ls -l $(which cp)

But the output is showing something else.

Why so ?

like image 351
Harsh Sharma Avatar asked Dec 14 '22 18:12

Harsh Sharma


1 Answers

ls does not take input from stdin. You can work around this if you need to by using 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.

like image 200
John Zwinck Avatar answered Dec 25 '22 12:12

John Zwinck