Re: Maybe offtopic: Dealing with filenames with blanks in a script
On Tuesday 27 April 2004 17:06, diego wrote:
> Hello, I know this is nearly offtopic, but need some help on a simple
> one line script as didn't find a simple solution through Google.
>
> I'm trying to manage files that have one or more blanks in their names
> (I'm not responsible for them being in such *nice* format...). Let's say
> I have the files:
>
> test 1
> test 2
> test 3
>
> I want a script to do some processing on them, let's simplify with a
> simple cat:
>
> for i in `ls *`; do cat $i; done
>
>
> but this will fail as it consider the blank as a separator for next
> filename.
>
> Thanx in advance.
I've had similar problems, and I ended up doing something like this:
# find . -type f -print0 | xargs -0 -i <command> <options> {}
The print0 argument to find uses a null character to signify the end of the
string, and the -0 argument to xargs tells it to look for that null, so
spaces are treated just like a-z.
Justin Guerin
Reply to: