View Single Post
Old Jun 28th, 2006, 1:48 PM   #1
MegaArcon
Programmer
 
MegaArcon's Avatar
 
Join Date: Aug 2005
Posts: 66
Rep Power: 0 MegaArcon is an unknown quantity at this point
String Substiution. Whitespace?

Hi all!

I've got a little bash script that basically takes my directory path to the "My Documents" folder. Instead of the space, I've inserted a special sequence that I want replaced with "\ " so that I can cd into that directory. However, I get an interesting result.

Here's the Script:
#!/bin/bash
MYDIR=/users/cs/study/gordon/MyxyXYWhitespacEYXyxDocuments
MYDIR=${MYDIR//xyXYWhitespacEYXyx/\\\ }
echo $MYDIR
cd $MYDIR
ls

Here's the output when I run my file:

/users/cs/study/gordon/My\ Documents
./test: line 5: cd: /users/cs/study/gordon/My\: No such file or directory

So the echo shows that the "\ " was put into the variable, but when I try and cd into it, it cuts off at the "My\". Does the string substitution put in something unique instead of just a whitespace? Am I using this correctly?

Thanks in advance for any insight.
__________________
Isn't that just the way life goes? If it's worth doing, it's NP-Hard. Todd Wareham - Memorial University of Newfoundland
MegaArcon is offline   Reply With Quote