[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Shell scripting



Pete Clarke declaimed:
> > The core loop is clearly 
> > 
> > >         for file in "$1"
> > >  do
> > >             filename=${file%.*}
> > >             echo "Adding $file to $filename.zip..."
> > >             $ZIP $ARGS "$filename" "$file" > /dev/null
> > > 
> > >             let "nofiles += 1"
> > >         done
> > 
> > Hint: try quoting your args when you run the script. Read the bash docs,
> > have fun.
> 
> Umm ... I have read the docs, and thought that
>     for file in "$1"
> was the correct way ..
Sorry to be so obtuse. By quoting your args, I meant when you ran it:

$ ./myscript "*"

instead of 

$ ./myscript *

In the first case, the glob is passed into the script, so $1 = * and all
is as you'd intended.

In the second case, bash helpfully expands the glob and passes the
result into the script, so $1 = <first item>

In any event, either $* or $@ will work just fine and suits your
intentions more accurately.

PM
-- 
Paul Mackinney
paul@mackinney.net



Reply to: