[wellylug] BASH scripting help required

David Antliff dave.antliff at paradise.net.nz
Fri May 7 14:09:06 NZST 2004


On Fri, 7 May 2004 andrej at paradise.net.nz wrote:

> Quoting "E.Chalaron" <e.chalaron at xtra.co.nz>:
>
> > /home/edouard/this\ dir/file\ test.txt
> > Can you rename the all lot such as
> > /home/edouard/thisdir/filetest.txt
> strip_blk.sh
> #!/bin/bash
> newname=`echo $1  |  sed "s/ /_/g"`
>
> you'll have to do something about the individual
> item, though, I'd suggest running it with
> a loop and getting deeper and deeper
> levels of directories...
>
> for i=1 to 7 (?)
> do
>   find --max-depth=$i -iname "* *" -exec strip_blk.sh {} \;
> done

A simple script that invokes itself for every subdirectory in the current
directory (with that subdir as the new current working dir) and then
renames all the files in the current directory should also work, provided
you don't have a directory structure so deep you run out of memory or
process ids...

It would be easier to write, with the trade off of consuming more
resources at run-time. It's essentially a depth first search at directory
level.

-- 
David.




More information about the wellylug mailing list