Unix管道进入ls [英] Unix pipe into ls

查看:64
本文介绍了Unix管道进入ls的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以为直到现在为止我都了解* nix管道...我有一个名为studio的可执行文件,它与我的Android Studio安装符号链接,并且我假设可以使用

I thought I understood *nix pipes until now... I have an executable called studio which symlinks to my install of Android Studio and I had assumed I could get the linked-to location with

which studio | ls -l

但这不起作用.它给我的相当于在当前目录中运行ls -l.

But that doesn't work. What it gives me is equivalent to having just run ls -l in the current directory.

如果我运行which studio,则会得到/home/me/bin/studio.如果运行ls -l /home/me/bin/studio,我将得到预期的输出,向我显示符号链接的位置.

If I run which studio, I get /home/me/bin/studio. And if I run ls -l /home/me/bin/studio I get the expected output showing me the symlink location.

那为什么管道版本不起作用?我对管子不满意吗?

So why doesn't the piped version work? What haven't I grokked about pipes?

推荐答案

要做到这一点,您需要xargs:

To do that you need xargs:

which studio | xargs ls -l

来自man xargs:

xargs-通过标准输入构建并执行命令行

xargs - build and execute command lines from standard input

要完全了解管道是如何工作的,可以阅读关于BASH中管道如何工作的简单解释是什么?:

To fully understand how pipes work, you can read What is a simple explanation for how pipes work in BASH?:

Unix管道连接STDOUT(标准输出)文件描述符 第一个过程到第二个的STDIN(标准输入).什么 然后发生的是,当第一个进程写入其STDOUT时, 第二步可以立即从STDIN读取输出.

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.

这篇关于Unix管道进入ls的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆