Mailinglist Archive: opensuse (2162 mails)
| < Previous | Next > |
[opensuse] OT: bash F1
- From: "Nick Zeljkovic" <nzeljkovic@xxxxxxxxx>
- Date: Sun, 17 Aug 2008 23:36:05 +0200
- Message-id: <000c01c900b1$42033e50$c609baf0$@com>
Hi Listmates,
Current code:
CURNUM=`ls /etc/apache2/sites-enabled|cut -d- -f1|tail -1`
NEWNUM=`expr $CURNUM + 1`
NUMLEN=`expr length $NEWNUM`
if [ -z $CURNUM ]
then
FID="001"
elif [ $NUMLEN -eq "1" ]
then
FID="00$NEWNUM"
elif [ $NUMLEN -eq "2" ]
then
FID="0$NEWNUM"
elif [ $NUMLEN -eq "3" ]
then
FID=$NEWNUM
Fi
Basically searches /etc/apache2/sites-enabled for filenames that are like:
001-site1
002-site2
And finds last value and then adds +1 to it. Let or expr doesn't want to
work with numbers starting with 0, makes sense, but I haven't found a way to
force it either, so I'm wondering if there is a clever solution to this,
bash-wise, or this should do it ? (taking there won't be 4 digits of sites;
more likely it will not hit 2 digits, but better be safe than sorry!)
Thanks.
--
Best regards,
Nick Zeljkovic
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx
Current code:
CURNUM=`ls /etc/apache2/sites-enabled|cut -d- -f1|tail -1`
NEWNUM=`expr $CURNUM + 1`
NUMLEN=`expr length $NEWNUM`
if [ -z $CURNUM ]
then
FID="001"
elif [ $NUMLEN -eq "1" ]
then
FID="00$NEWNUM"
elif [ $NUMLEN -eq "2" ]
then
FID="0$NEWNUM"
elif [ $NUMLEN -eq "3" ]
then
FID=$NEWNUM
Fi
Basically searches /etc/apache2/sites-enabled for filenames that are like:
001-site1
002-site2
And finds last value and then adds +1 to it. Let or expr doesn't want to
work with numbers starting with 0, makes sense, but I haven't found a way to
force it either, so I'm wondering if there is a clever solution to this,
bash-wise, or this should do it ? (taking there won't be 4 digits of sites;
more likely it will not hit 2 digits, but better be safe than sorry!)
Thanks.
--
Best regards,
Nick Zeljkovic
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx
| < Previous | Next > |