如何将此路径传递给 bash 函数?

发布于 2024-07-14 09:10:57 字数 404 浏览 2 评论 0原文

我在移动到名称中带有空格的目录时遇到了麻烦,但我只是认为这是 Cygwin 的问题并解决了它。

然后我发现我可以创建到这些目录的符号链接,这让我可能认为它不是 Cygwin。 然后我记得我为 cd 创建了一个别名,它将列出目录内容并看到了这一点:

cdls { cd $1; ls; }
alias cd='cdls'

所以问题是当我尝试这样做时它失败了:

$ cd /cygdrive/c/Program\ Files/
bash: cd: /cygdrive/c/Program: No such file or directory

我可以看到空格导致路径被分割分成多个参数,但如何将它们再次连接在一起?

I've been having trouble moving to directories with spaces in the name, but it I just figured it was a problem with Cygwin and worked around it.

Then I found that I could create symbolic links to those directories which made me maybe think it wasn't Cygwin. Then I remembered I created an alias for cd that would list the directory contents and saw this:

cdls { cd $1; ls; }
alias cd='cdls'

So the problem is when I try this it fails:

$ cd /cygdrive/c/Program\ Files/
bash: cd: /cygdrive/c/Program: No such file or directory

I can see that the space is causing the path to be split into multiple arguments, but how do I join them together again?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

三五鸿雁 2024-07-21 09:10:57

引用它:

cdls { cd "$1"; ls; }

在 bash 中引用可能会变得很麻烦,因为有多个级别的解释,但这通常只是稍微玩一下而已。

Quote it:

cdls { cd "$1"; ls; }

Quoting in bash can get hairy, since there's multiple levels of interpretation, but it's usually just a matter of playing with it a bit.

谜兔 2024-07-21 09:10:57

尝试:

cdls() { cd "$1"; ls; }

Try:

cdls() { cd "$1"; ls; }
难如初 2024-07-21 09:10:57

看来我只需要解释一下问题就能得到答案。 我的解决方案是:

cdls () { cd "$*"; ls ; }
alias cd='cdls'

简单。

Looks like I just needed to explain the problem for the answer to come to me. My solution is:

cdls () { cd "$*"; ls ; }
alias cd='cdls'

Simple.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文