Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cd(1) and variables with spaces (cygwin)

I've been having quite an unusual problem. In my .bashrc file, I have set a variable to a path name with spaces in it. I had a feeling this would cause problems, but I played around with setting an alias in a similar way and got it to work like so:

alias npp="\"/cygdrive/c/Program Files (x86)/Notepad++/notepad++.exe\""

Now, I thought I could use the same trick for my environment variable -

export PRO="\"/cygdrive/c/Program Files (x86)\""

This worked. Kind of.

[myName]  
$ echo $PRO  
"/cygdrive/c/Program Files (x86)"

[myName]  
$ cd $PRO  
bash: cd: "/cygdrive/c/Program: No such file or directory

I've tried placing an escape before the space with and without removing the double quotes, I've tried single quotes with and without the escape. I've tried using grave accents as quotes. I've tried just the escape, I've tried

export PRO=/cygdrive/c/Program\\\ Files\\\ \\\(x86\\\)

None of this has worked. The only thing that has was -

export PRO="/cygdrive/c/Program Files (x86)"
$ cd "$PRO"

Ultimately, I'm trying to find a way to make my variable work without placing quotes around it every single time I type the variable. Having run out of ideas entirely I came here hoping for someone to be able to help me.

like image 982
user1850009 Avatar asked Nov 18 '25 12:11

user1850009


1 Answers

I got around this with wildcards:

export PRO="/cygdrive/d/Program*Files/"

like image 127
chris Avatar answered Nov 20 '25 03:11

chris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!