开发者

How to pipe the output of the Linux which command into the Linux file command?

开发者 https://www.devze.com 2023-02-11 01:23 出处:网络
$ which file /usr/bin/file $ file /usr/bin/file /usr/bin/file: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV)开发者_开发百科, dynamically linked (uses shared libs), for GNU/Linux 2.6.15, str
$ which file
/usr/bin/file
$ file /usr/bin/file
/usr/bin/file: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV)开发者_开发百科, dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped

Why does this not work?

$ which file | file

Usage: file [-bcikLhnNrsvz0] [-e test] [-f namefile] [-F separator] [-m magicfiles] file...
   file -C -m magicfiles

Try file --help for more information.


You're probably looking for xargs or shell expansion. Try:

$ which file | xargs file

or

$ file `which file`


file expects its arguments on the command line, not on its standard input, unless you tell it otherwise:

$ which file | file -f -

Alternatively:

$ file `which file`

Or, for completeness:

$ which file | xargs file


Try backquotes instead, e.g.

$ file `which python`
/usr/bin/python: symbolic link to `python2.6'

Your example doesn't work because your pipe is sending the output of the which command to the stdin of the file command. But file doesn't work on stdin - it works on a command line argument.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号