Whitespace in Directory Problem with a script

Hey everyone...

I'm writing a little script and I'm having a little trouble with the code included herein...

I am trying to TOUCH a file (ya, that's it), that so happens to be in a directory structure that contains whitespace, so when I run the script (this is part of a much larger script, so please don't tell me to use perl, python, C or any other language, it's a moot point) it spits out:

vanjos:~ vanjos$ bash -x temp
+ CAMP_NAME='Metro Toronto'
+ WORKING_DIR='"/Users/vanjos/Documents/Real Estate/Sales and Leads/Victor'\''s Docs/'
+ i=3
++ echo '"/Users/vanjos/Documents/Real' Estate/Sales 'and 'Leads/Victor'\''s' Docs//Metro 'Toronto_3"'
++ sed 's/ /\\ /g'
++ sed 's/\/\/\"//g'
+ FILE='"/Users/vanjos/Documents/Real\ Estate/Sales\ and\ Leads/Victor'\''s\ Docs//Metro\ Toronto_3"'
+ touch '"/Users/vanjos/Documents/Real\' 'Estate/Sales\' 'and\' 'Leads/Victor'\''s\' 'Docs//Metro\' 'Toronto_3"'
touch: "/Users/vanjos/Documents/Real\: No such file or directory
touch: Estate/Sales\: No such file or directory
touch: Leads/Victor's\: No such file or directory
touch: Docs//Metro\: No such file or directory
vanjos:~ vanjos$ ls
and
temp
Toronto_3
vanjos:~vanjos$

As you can see, it separates all the files and send EACH as an argument to touch.  I have tried to manipulate that variable to no avail, but can't find a way to make this work.  I just want to make sure that under the directory:

"/Users/vanjos/Documents/Real Estate/Sales and Leads/Victor's Docs/"

I get a file:

Metro_Toronto_3

Thanks,
Victor
CAMP_NAME="Metro Toronto"
WORKING_DIR="\"/Users/vanjos/Documents/Real Estate/Sales and Leads/Victor's Docs/"
i=3

FILE=`echo ${WORKING_DIR}/${CAMP_NAME}_${i}\" | sed 's/\/\/\"//g' | sed 's/ /\\\ /g'`

touch $FILE

Open in new window

LVL 1
wii_injuryAsked:
Who is Participating?
 
medveddConnect With a Mentor Commented:
Can you use just double quote, i.e.:

CAMP_NAME="Metro Toronto"
WORKING_DIR="/Users/vanjos/Documents/Real Estate/Sales and Leads/Victor's Docs/"
0
 
medveddCommented:
replace last line:

touch "$FILE"
0
 
wii_injuryAuthor Commented:
It's much, much closer... And the syntax would work on command line:

vanjos:~ vanjos$ touch "/Users/vanjos/Documents/Real Estate/Sales and Leads/Victor's Docs//Metro Toronto_3"
vanjos:~ vanjos$ ls "/Users/vanjos/Documents/Real Estate/Sales and Leads/Victor's Docs/"
Metro Toronto_3
vanjos:~ vanjos$

But it does not work inside the script:

vanjos:Women's Fitness vanjos$ ./temp
touch: "/Users/vanjos/Documents/Real Estate/Sales and Leads/Victor's Docs//Metro Toronto_3": No such file or directory

I'm going to keep testing, but any help would be appreciated.
0
 
medveddCommented:
Something is different between command line and script. Please double-check.
0
 
wii_injuryAuthor Commented:
FROM SCRIPT

vanjos:~ vanjos$ sh -x temp
+ CAMP_NAME='Metro Toronto'
+ WORKING_DIR='"/Users/vanjos/Documents/Real Estate/Sales and Leads/Victor'\''s Docs/'
+ i=3
+ touch '"/Users/vanjos/Documents/Real Estate/Sales and Leads/Victor'\''s Docs//Metro Toronto_3"'
touch: "/Users/vanjos/Documents/Real Estate/Sales and Leads/Victor's Docs//Metro Toronto_3": No such file or directory

FROM COMMAND LINE:

vanjos:~ vanjos$ touch '"/Users/vanjos/Documents/Real Estate/Sales and Leads/Victor'\''s Docs//Metro Toronto_3"'
touch: "/Users/vanjos/Documents/Real Estate/Sales and Leads/Victor's Docs//Metro Toronto_3": No such file or directory

0
All Courses

From novice to tech pro — start learning today.