重击pwd并用管道打开不起作用 [英] Bash pwd and open with pipe not working

查看:107
本文介绍了重击pwd并用管道打开不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习如何在bash中使用I/O重定向,并尝试了一些类似管道的示例:

I'm learning how to work with I/O Redirection in bash and tried some examples with the pipe like:

pwd | say
ls -l | grep "staff" > out.txt

但是当我尝试通过管道重定向同时使用pwdopen时,该命令将失败,并且我只会收到open的用法.

But when I try using both pwd and open using pipe redirection, the command fails and I just receive open usage.

我正在尝试的是:pwd | open

从bash打开当前目录的正确方法是什么?

What is the correct way to open the current directory from bash?

推荐答案

借助事后观察,有 2个不同的答案:

A:要回答OP的问题 ,以 了解管道 I/O流 :

A: To answer the OP's question as asked with a view to understanding pipes and I/O streams:

echo . | xargs open

# Equivalent solution, using the special "$PWD" shell variable.
printf '%s\0' "$PWD" | xargs -0 open

是通过管道将当前目录路径传递到open CLI 的最健壮方法,以便在OSX的文件系统浏览器GUI应用程序.

is the most robust way to pass the current directory's path to the open CLI via a pipe in order to have it open that directory in OSX's file-system-browser GUI application, Finder.

请注意,pwd | xargs open并不健壮,因为如果当前目录路径具有嵌入式空格,它将失败-请参见下文.

Note that pwd | xargs open is NOT robust, because it fails if the current directory path has embedded whitespace - see below.

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