[svlug] Working with spaces in shell scripts
Fabrizio Bertocci
fabriziobertocci at gmail.com
Tue Dec 14 15:48:13 PST 2004
Never give up ...
Usually if you enclose in double quotes (") the variable that contains
the directory name, it works...
i.e.:
foo="Monkey Joe"
rm "$foo/abc.txt"
Unfortunately the following command won't work:
for i in `find /my_root -type f`; do ...
because there's no way to distinguish between a space in the directory
name and the separator between two files.
In this case you can use the 'find' command with the -exec option: the
following command removes all the files ending with '.txt' from
/my_root directory and all the sub-dirs, including directories that
contains spaces:
find /my_root -type f -name "*.txt" -exec rm -f {} \;
Fabrizio
On Tue, 14 Dec 2004 15:15:15 -0800, Nathan <nathank at netflip.com> wrote:
> I want to remove the some files from inside a bunch of directories with
> spaces in the names. But when my script hits a directory with a space in
> its name the script will treat it as two separate directories (ie
> "Monkey Joe" becomes "Monkey" and "Joe"). Can this even be done with a
> shell script? Should I break down and use perl?
>
> Thanks,
> Nathan
>
> _______________________________________________
> svlug mailing list
> svlug at lists.svlug.org
> http://lists.svlug.org/lists/listinfo/svlug
>
More information about the svlug
mailing list