[Discuss] bash problem
Rajiv Khaneja
rajivk at sparklit.com
Thu Aug 16 15:45:27 PDT 2007
Your problem is with this line
"for DIR in `find -type d`; do"
The out put of find is being tokenized by space and newlines... so with the
directory "foo bar" DIR is being set to foo first then on the next
iteration bar.
I think you can do something like
IFS=$'\n'
and bash will only tokenize on new lines.
Other than that I can't think of anything... I find it easier to just use
perl instead of dealing with bash string manipulation
--
____ _ _ _ _
/ ___| _ __ __ _ _ __| | _| (_) |_ Rajiv Khaneja
\___ \| '_ \ / _` | '__| |/ / | | __| Sparklit
___) | |_) | (_| | | | <| | | |_ ph: 877.275.5480 x 811
|____/| .__/ \__,_|_| |_|\_\_|_|\__| fax: 604.677.6049
|_| www.sparklit.com <RajivK at Sparklit.com>
On 8/16/07, pw <p.willis at telus.net> wrote:
>
> #!/bin/bash
>
> export START=`pwd`
>
> for DIR in `find -type d`; do
> cd $DIR;
> cd $START;
> done
>
> #END IF SCRIPT
>
>
>
> The code above works fine as long as there are no
> spaces in $DIR .
>
> How can I ensure that bash changes into
> directories where the path contains spaces?
>
> So far I've tried:
>
> cd "$DIR"
>
> and:
>
> DIR=`echo $DIR | sed -e "s/\ /\\\ /g"`
> cd $DIR
>
>
> Any thoughts?
>
> Peter
>
> _______________________________________________
> Discuss mailing list
> Discuss at vlug.org
> http://ladybug.vlug.org/cgi-bin/mailman/listinfo/discuss
>
More information about the Discuss
mailing list