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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
medveddCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.