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

Paul Howarth paul at city-fan.org
Wed Mar 1 21:53:21 UTC 2006


On Wed, 2006-03-01 at 16:38 -0500, Michael Wiktowy wrote:
> Greetings all,
> 
> I have done a fair amount of experimentation and Googling trying to
> find an answer to this and was wondering if some of the bash-scripting
> gurus out there could give me a hand.
> 
> I am trying to make a script that will accept a wildcard to match a
> bunch of files and iterate over those absolute filenames; running the
> command once per filename. It is fairly straight-forward to do so when
> the filesnames don't have spaces but I haven't been able to find the
> magic combination that doesn't treat every space as a list separator. 
> The closest I have gotten is to use the following script:
> 
> #!/bin/bash
> find $* -print0 | xargs -0 -I % command_to_iterate_over %

Try "$@" instead of $*

Paul.





More information about the fedora-list mailing list