[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
On Sat, Nov 05, 2005 at 02:27:41PM -0500, Art Alexion said:
> Paul L. Snyder wrote:
>
> > #!/bin/bash
> > PREFIX=${1}
> > shift
> > for file in ${*}
> > do
> > mv -v ${file} ${PREFIX}$file
> > done
> >
> Thanks, Paul. Worked fine. Now I have to figure out *why* it worked,
> that is, why it knew that {*} was the second argument, and why I needed
> to assign the variable PREFIX to ${1}.
$* is just a shell builtin meaning 'the rest of the arguments'. So in
order not to have the first argument get slurped in (and thus lose
chipmunk- as a special argument) you first reassign it to a more
permanent variable, and then 'shift' the command line, to get rid of
chipmunk-. Whatever's left is in $*, and gets expanded by the for loop.
See also $@, which gets white space expanded, unlike $*, which gets IFS
expanded (the fun that can be had with those differences).
--
--------------------------------------------------------------------------
| Stephen Gran | Always be sincere, even when you |
| steve@lobefin.net | don't mean it. -Irene Peter |
| http://www.lobefin.net/~steve | |
--------------------------------------------------------------------------
Attachment:
signature.asc
Description: Digital signature
___________________________________________________________________________ Philadelphia Linux Users Group -- http://www.phillylinux.org Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug