Argggg。我一直在用这种愚蠢的问题所困扰了几天,我无法找到答案。
Argggg. I've been struggling with this stupid problem for days and I can't find an answer.
我使用的是Mac OS X的BASH,我想创建一个简单的可执行脚本文件,它的运行时会切换到另一个目录。但是,路径到该目录中有空格。如何赫克你做到这一点?这是我有...
I'm using BASH on Mac OS X and I'd like to create a simple executable script file that would change to another directory when it's run. However, the path to that directory has spaces in it. How the heck do you do this? This is what I have...
文件的名称: CD code 的
文件内容: CD〜/我的code
现在理所当然的,这不是一个很长的路径名,但我的实际路径是五个目录深,这些目录四种路径中有空格。
Now granted, this isn't a long pathname, but my actual pathname is five directories deep and four of those directories have spaces in the path.
顺便说一句,我试过 CD〜/我的code和 CD〜/我的\\ code 键,这些都不奏效。
BTW, I've tried cd "~/My Code" and cd "~/My\ Code" and neither of these worked.
推荐答案在双引号的路径,你停止波浪线扩展。因此,有几个方法可以做到这一点:
When you double-quote a path, you're stopping the tilde expansion. So there are a few ways to do this:
cd ~/"My Code" cd ~/'My Code'代字号不在这里引用,所以波浪线扩展仍将运行。
The tilde is not quoted here, so tilde expansion will still be run.
cd "$HOME/My Code"您还可以扩大双引号字符串内的环境变量;这基本上是什么波浪线扩展是做
You can expand environment variables inside double-quoted strings; this is basically what the tilde expansion is doing
cd ~/My\ Code您也可以使用反斜杠转义特殊字符(如空格)。
You can also escape special characters (such as space) with a backslash.
更多推荐
BASH脚本cd到目录与路径空间
发布评论