Mailinglist Archive: opensuse (2740 mails)

< Previous Next >
[opensuse] bash - handling expansion of parameters on the command line?
  • From: "David C. Rankin" <drankinatty@xxxxxxxxxxxxxxxxxx>
  • Date: Mon, 01 Dec 2008 20:25:44 -0600
  • Message-id: <49349CA8.7050609@xxxxxxxxxxxxxxxxxx>
Bash wizards:

I have run across another quandary. I am trying to get a filespec from
the
command line like:

./scriptname file1*

and file name expansion occurs before I can assign the filespec to a
variable.
I want to be able to grab the 'file1*' filespec without having to require that
it be enclosed in single quotes (./scriptname 'file1*'). I'm using the filespec
like:

FILESPEC=$1
NEWNAME=$2

for i in $(ls ${FILESPEC}); do
echo -n "moving $i --> ${NEWNAME}.${i##*.}"
if mv $i ${NEWNAME}.${i##*.}; then
echo ".........Success"
else
echo ".........Failed"
fi
done

Can I do it, or do I have to look at handling the expanded command line
in
another way like an array or something? The easiest way would probably be to
swap NEWNAME to $1 and then do $2 until I run out of parameters, but that would
defeat my preference of the command line being ./rename what to-what. What is
the best way to skin this cat? (I've also learned that the expression can be
'wash that pig' in some parts as well)

Thanks.


--
David C. Rankin, J.D.,P.E. | openSoftware und SystemEntwicklung
Rankin Law Firm, PLLC | Countdown for openSuSE 11.1
www.rankinlawfirm.com | http://counter.opensuse.org/11.1/small
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx

< Previous Next >