如何将此路径传递给 bash 函数?
我在移动到名称中带有空格的目录时遇到了麻烦,但我只是认为这是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
引用它:
在 bash 中引用可能会变得很麻烦,因为有多个级别的解释,但这通常只是稍微玩一下而已。
Quote it:
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.
尝试:
Try:
看来我只需要解释一下问题就能得到答案。 我的解决方案是:
简单。
Looks like I just needed to explain the problem for the answer to come to me. My solution is:
Simple.