Search code examples
bashpathcygwin

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'; I tried to wrap the path in to double quotes but it is not working either.

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

How would u fix that?


Solution

  • Surround your variable with quotes:

    $ "$startup"
    

    You should always quote variables to be safe. You can refer to this page for more details.

    As it states in the first paragraph: "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)."

    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.