On Sunday 17 August 2008 14:36, Nick Zeljkovic wrote:
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,
Expr does not treat leading zeroes as special. But beware that BASH's "let" built-in, which is vaguely similar to "expr," will treat such numbers as octal. % expr 20 + 1 21 % expr 020 + 20 40 % expr 0020 + 020 + 20 60
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!)
I would check what's coming out of your "cut" command. It may not be what you think.
Thanks.
-- Best regards, Nick Zeljkovic
Randall Schulz -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org