Bash 路径包含 space 没有这样的文件或目录
Bash path contained space no such file or directory
根据这个问题How to input a path with a white space?我已经声明了这样的目录路径:
startup='/cygdrive/c/Users/Me/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup';
我试着用双引号将路径括起来,但它也不起作用。
但由于某些原因,当我输入 $startup
时出现错误:
$ $startup
bash: /cygdrive/c/Users/Alex/AppData/Roaming/Microsoft/Windows/Start: No such file or directory
你会如何解决这个问题?
用引号括起您的变量:
$ "$startup"
为了安全起见,您应该始终引用变量。您可以参考this页面了解更多详情。
如第一段所述:"When referencing a variable, it is generally advisable to enclose its name in double quotes. This prevents reinterpretation of all special characters within the quoted string -- except $, ` (backquote), and \ (escape)."
您还可以参考 this 页面,其中指出:基本的经验法则是您应该在每个扩展名中加双引号。这可以防止不需要的单词拆分和通配。如有疑问,请引用。
根据这个问题How to input a path with a white space?我已经声明了这样的目录路径:
startup='/cygdrive/c/Users/Me/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup';
我试着用双引号将路径括起来,但它也不起作用。
但由于某些原因,当我输入 $startup
时出现错误:
$ $startup
bash: /cygdrive/c/Users/Alex/AppData/Roaming/Microsoft/Windows/Start: No such file or directory
你会如何解决这个问题?
用引号括起您的变量:
$ "$startup"
为了安全起见,您应该始终引用变量。您可以参考this页面了解更多详情。
如第一段所述:"When referencing a variable, it is generally advisable to enclose its name in double quotes. This prevents reinterpretation of all special characters within the quoted string -- except $, ` (backquote), and \ (escape)."
您还可以参考 this 页面,其中指出:基本的经验法则是您应该在每个扩展名中加双引号。这可以防止不需要的单词拆分和通配。如有疑问,请引用。