[TriLUG] RE with bash

William Sutton william at trilug.org
Mon Oct 23 12:05:30 EDT 2006


try find . -type d -print0 |xargs -0 cd ?  the -print0 and xargs -0 tell 
it to null terminate each string rather than space terminate....

-- 
William Sutton

On Mon, 23 Oct 2006, Joseph Mack NA3T wrote:

> I need a script to find directories in a tree and cd to 
> them. Some of the directory names have blanks in them, eg 
> "Flash Player". So if a directory has the subdirectories
> 
> ./Flash Player
> ./foo
> 
> then a command like
> 
> 
> IFS=./; for directory in `find ./ -type d | xargs`
> 
> will give
> directory="Flash Player "
> then
> directory="foo "
> 
> in bash to cd to "Flash Player " I have to cd to "Flash\ 
> Player ". I can substitute the first blank with
> 
> directory=${directory//\ /\\}
> 
> but there is a 2nd blank in the directory name and I get
> 
> directory="Flash\ Player\ "
> 
> In this construct the $ symbol does not work as an EOL 
> symbol, so I can't selectively remove the last blank.
> I tried substituting the blanks between [:alphanum:] 
> [:alphanum:] but there doesn't seem to be any way to replace 
> the char you matched (here the 'h' and the 'P') as you can 
> in perl.
> 
> Any ideas on changing "Flash Player " to "Flash\ Player"
> (or "Flash\ Player ") in a bash script?
> 
> Thanks Joe
> 
> 



More information about the TriLUG mailing list