LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   passing variable (a path) with spaces (https://www.linuxquestions.org/questions/linux-general-1/passing-variable-a-path-with-spaces-736244/)

aolong 06-28-2009 02:43 PM

passing variable (a path) with spaces
 
OK, I searched the forums and read that this should work, but it fails...

path="/media/My Passport"
cd $path
ls .

returns "./dupes.sh: line 19: cd: /media/My: No such file or directory"

but, if I escape the space it still fails:

path="/media/My\ Passport"

I have tried all variations I can think of without success... renaming the dir, mounting differently, or linking are not options, I need to deal with paths with spaces...

Andrew

colucix 06-28-2009 03:10 PM

You have to put quotes around the value when you use it:
Code:

cd "$path"

aolong 06-28-2009 05:50 PM

Thank you. That works.


All times are GMT -5. The time now is 04:19 AM.