How to handle passing filenames with spaces and wildcards into bash scripts?

Michael Wiktowy michael.wiktowy at gmail.com
Wed Mar 1 22:37:11 UTC 2006


On 3/1/06, Paul Howarth <paul at city-fan.org> wrote:
>
> On Wed, 2006-03-01 at 16:38 -0500, Michael Wiktowy wrote:
> > #!/bin/bash
> > find $* -print0 | xargs -0 -I % command_to_iterate_over %
>
> Try "$@" instead of $*
>
> Paul.



I knew there was something obvious that I was missing.

The following:
#!/bin/bash
find "$@" -print0 | xargs -0 -I % command_to_iterate_over %

Does exactly what I needed when calling it with unquoted but properly
escaped argument like:
./script /path/to/filenames\ with\ spaces* /other/path\ with\ spaces/to\
other\ filenames\ with\ spaces*

It doesn't work with quoted command-line parameters with wildcards in them
but that's OK to me. I will have to experiment a bit more with that and put
$@ in my mental toolbox.

Thank you kindly, Paul and Robert!

/Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/fedora-list/attachments/20060301/76c3b97a/attachment-0001.htm>


More information about the fedora-list mailing list