1

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?

Community
  • 1
  • 1
Sergino
  • 10,128
  • 30
  • 98
  • 159

1 Answers1

4

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.

Julian
  • 2,837
  • 17
  • 15
  • Yeah that is working but why in is not working without a quotes? – Sergino Dec 15 '15 at 13:17
  • The shell performs word-splitting on the result of a parameter expansion, so you need to quote the string when you are defining it *and* when you expand it. – chepner Dec 15 '15 at 16:19