[plug] Simple bash scripting problem

Craig Ringer craig at postnewspapers.com.au
Mon Oct 10 19:26:32 WST 2005


Richard Meyer wrote:

>>>>#!/bin/bash
>>>>for file in $1; do
>>>>        ls -l $file
>>>>done
>>>>        
>>>>
>>> 
>>>and call it as below [ with a quoted glob - CR ]
>>>      
>>>
That's doing the glob expansion in the called script, not in the 
surrounding shell. That could occasionally result in surprising effects, 
especially when working with a command that works like:

command target list-of-files

or

command list-of-files target

The UNIX convention is to expand globs in the shell before executing a 
command. While that has some downsides, it does ensure glob behaviour is 
always consistent. The usage you suggest breaks that convention in ways 
that could occasionally get _really_ confusing.

--
Craig Ringer



More information about the plug mailing list