Bash路径包含空间,没有这样的文件或目录 [英] Bash path contained space no such file or directory
问题描述
根据此问题如何使用空白?我已经声明了这样的目录路径:
As per this question How to input a path with a white space? I have declared a directory path like that:
startup='/cygdrive/c/Users/Me/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup';
我试图将路径换成双引号,但它也不起作用.
startup='/cygdrive/c/Users/Me/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup';
I tried to wrap the path in to double quotes but it is not working either.
但是由于某些原因,当我键入$startup
时出现错误:
But for some reason when I am typing $startup
I am getting an error:
$ $startup
bash: /cygdrive/c/Users/Alex/AppData/Roaming/Microsoft/Windows/Start: No such file or directory
您将如何解决?
推荐答案
用引号将变量引起来:
$ "$startup"
为了安全起见,应始终引用变量.您可以参考此页面以获取更多详细信息.
You should always quote variables to be safe. You can refer to this page for more details.
如第一段所述:在引用变量时,通常建议将其名称括在双引号中.这样可以防止重新解释带引号的字符串中的所有特殊字符-除$,`(反引号)和\(转义)."
您还可以参考此页面,其中指出:基本的经验法则是您应该对每个扩展名都加双引号.这样可以防止不必要的单词拆分和乱码.如有疑问,请引用.
You can also refer to this page which states: The basic rule of thumb is that you should double-quote every expansion. This prevents unwanted word splitting and globbing. When in doubt, quote it.
这篇关于Bash路径包含空间,没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!