Re: help, help scripting masters

From: David J. Weller-Fahy <dave-lists-aklug@weller-fahy.com>
Date: Sun Mar 21 2004 - 22:41:43 AKST

* captgoodnight@acsalaska.net <captgoodnight@acsalaska.net> [2004-03-21 22:00 -0900]:
> Nope, has to be the path complete. I've used all forms of quotes too.
> The script takes the path/folder name, places it in a variable, then
> uses it within the script for all sorts of actions. The only way I've
> been able to get around this is using a while loop
>
> yup="folder with spaces"
> foo=($(echo $yup | sed 's/ /\\ /g'))
> cd `echo -n ${foo[*]}` #nope, [0] only
> cd $(echo -n ${foo[*]}) #nope, [0] only
>
> but the escapes get removed as soon as the variable is used. I would
> really like to get rid of the while loop method, too messy.

Ok, I *think* I understand, but just to make sure:

You're trying to pass a multiple level path (or single level) with
spaces in it on the command line, or by assigning directly to a
variable, such as:

command --folder "/home/whoever/folder with spaces"
or
command --folder "folder with spaces"

If I've got that part, then you're trying to do multiple things with
that folder (rename based on a naming scheme, etc.) within a bash
script. Now, I believe (looking at the above snippet) that the problem
may be in the details of the script. Try the following snippet,
replacing 'folder with spaces' with a folder you want to manipulate:

#v+
FWS="folder with spaces"
pwd # show current directory
cd ${FWS} # note the lack of double quotes, this line shouldn't work
pwd
cd "${FWS}" #note the double quotes, this line should work
pwd
#v-

If the latter 'cd' command works (as the pwd command following it will
show) then just remember that whenever you're referring to that variable
as an argument to a command use the "${VARIABLE}" syntax.

I've found sticking to the ${VARIABLE} syntax (and including double
quotes around it when using it as an argument) when writing scripts
saves some headaches. Also, if you're trying to pass the folder with
spaces on the command line, try surrounding it with double quotes. That
allows bash to see the entire name (including the spaces) as the first
arguments.

> hope that makes sense, kinda hard for me to explain.

;]
I may be misunderstanding your problem completely. If so, show me the
complete script along with an example path name, and I'll try it on my
system to see if I can figure it out.

Regards,

-- 
dave [ please don't CC me ]
---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.
Received on Sun Mar 21 22:41:13 2004

This archive was generated by hypermail 2.1.8 : Sun Mar 21 2004 - 22:41:13 AKST