linux - Unix管道到ls

我以为我直到现在才理解 *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/

相关文章:

linux - 如何在 unix 中解压 tar.bz 文件?

linux - 检查 VT-x 是否已激活而无需在 Linux 中重新启动?

c - 无论如何要从命令行获取c程序的返回值?

c - 如何在 Linux 中创建高分辨率计时器来测量程序性能?

Linux 上的 C++ 开发 - 我从哪里开始?

linux - 如何将上下文后的 grep 设置为 "until the next blank li

linux - 内联 if shell 脚本

c++ - 将字符串作为指针或文字传递时,strcmp() 返回值不一致

linux - 如何在 Bash 字符串中添加新行?

c - 使用 gdb 将地址转换为行