You could stick it in "find" and have find do the recursion.
find . -type d -exec your_script {} \;
--
Smoot Carl-Mitchell
Computer Systems and
Network Consultant
sm...@tic.com
+1 480 922 7313
cell: +1 602 421 9005
--
ubuntu-users mailing list
ubuntu...@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
20090627 1524 GMT-5
If you have a folder like:
/home/user/folder name
and you want to cd to it
cd /home/user/folder\ name
then wouldnt you want to scan the directory for any folder with the
space first, then remove the spaces, and the rescan again so it "could'
go into the next directory?
wade
--
Registered Linux User: #480675
Linux since June 2005
Sure you can. Just enclose the $1 argument in your script in double
quotes. The cd will then take it as a single argument and do the right
thing. It is the shell that is expanding the $1 and then seeing the
whitespace as argument separators.
This will break for directories that are renamed, because the script
will rename directories before they have been examined. By adding the
'-depth' option, you tell the find command to use 'depth-first' - i.e.
to process the contents of a directory before it processes the
directory.
So Soren can run
find . -depth -type d -exec your_script "{}" \;
after remembering to quote the parameter $1 in the script.
Making the existing script recursive is more complex, because it has to
handle the recursion itself. However, it does appear that the loop code
find . -depth -type d -print | while read d
do
pushd "$d"
...
popd
done
will work even for directories that have embedded spaces (where the line
'...' represents Soren's original code). Note that I use pushd/popd
because:
* the original code assumes that it is in the directory to be processed
* directory names are relative to the directory where the find started
The pushd needs quotes because otherwise a directory name with spaces
will still be split by the shell.
The code 'find . -type d -print | while read d ' works (unless the file
name DOES include a newline), because find prints a newline ("\n" or
0x0a) between file names, and the shell built-in read function uses
newline as its default delimeter.
Tim
--
Tim Frost <timf...@xtra.co.nz>
> > You could stick it in "find" and have find do the recursion.
> >
> > find . -type d -exec your_script {} \;
>
> This will break for directories that are renamed, because the script
> will rename directories before they have been examined. By adding the
> '-depth' option, you tell the find command to use 'depth-first' - i.e.
> to process the contents of a directory before it processes the
> directory.
Good point. I missed the fact he is also renaming directories.
> So Soren can run
> find . -depth -type d -exec your_script "{}" \;
> after remembering to quote the parameter $1 in the script.
--
Smoot Carl-Mitchell
Computer Systems and
Network Consultant
sm...@tic.com
+1 480 922 7313
cell: +1 602 421 9005
--