[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: help with quoting/expansion in bash



On Sun, Feb 12, 2006 at 01:23:47PM -0600, David Berg wrote:
> I'm trying to write a for loop that descends into a list of
> directories and runs a command.  I can't seem to get the quoting right
> though.  Most of the directories have spaces and they are making
> things difficult for me.  Here is what I have:
> 
> for DIR in dir\ 1 dir\ 2 dir\ 3; do
>         cd $DIR
>         pwd
>         cd ..
> done
> 
> The spaces in $DIR aren't escaped.
> 
> Any help, including a pointer to the relevant part of TFM, is much appreciated.
> 
> --Dave
Hi Dave,
the 'magic' is to never bother with escaped space!! Just use double
quotes!

for DIR in "dir 1 dir 2 dir 3"; do
	cd "$DIR"
	pwd
	cd ..
done
or something like it
Cheers,
Kev
-- 
|  .''`.  == Debian GNU/Linux == |       my web site:       |
| : :' :      The  Universal     | debian.home.pipeline.com |
| `. `'      Operating System    | go to counter.li.org and |
|   `-    http://www.debian.org/ |    be counted! #238656   |
|     my keysever: pgp.mit.edu   |     my NPO: cfsg.org     |

Attachment: signature.asc
Description: Digital signature


Reply to: