我以为我直到现在才理解 *nix 管道...我有一个名为 studio
的可执行文件,它符号链接(symbolic link)到我安装的 Android Studio
并且我以为我可以得到用
which studio | ls -l
但这不起作用。它给我的效果相当于在当前目录中运行 ls -l
。
如果我运行 which studio
,我会得到 /home/me/bin/studio
。如果我运行 ls -l/home/me/bin/studio
我会得到预期的输出,显示符号链接(symbolic link)的位置。
那么为什么管道版本不起作用?我对管道有什么不了解的地方?
最佳答案
为此,您需要 xargs
:
which studio | xargs ls -l
来自 man xargs
:
xargs - build and execute command lines from standard input
要全面了解管道的工作原理,您可以阅读 What is a simple explanation for how pipes work in BASH? :
A Unix pipe connects the STDOUT (standard output) file descriptor of the first process to the STDIN (standard input) of the second. What happens then is that when the first process writes to its STDOUT, that output can be immediately read (from STDIN) by the second process.
https://stackoverflow.com/questions/18210956/