On Sun, 17 Aug 2008, Nick Zeljkovic wrote:-
Hi Listmates,
Current code: CURNUM=`ls /etc/apache2/sites-enabled|cut -d- -f1|tail -1`
# -r allows sed to use regex in the script, # ^0+ matches any number of leading zeros CURNUM=$(ls /etc/apache2/sites-enables|cut -d- -f1|tail -1|sed -r "s#^0+##")
NEWNUM=`expr $CURNUM + 1`
# no need for expr to increment $NEWNUM NEWNUM=$(( ${CURNUM} + 1)) If CURNUM is empty, or not a number, NEWNUM will be assigned a value of "1"
NUMLEN=`expr length $NEWNUM`
No need for that line, unless you actually need $NUMLEN at some other point. If you do, you don't need to use expr: # return the length of the variable $NEWNUM NUMLEN=${#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
And these can be reduced to one line: FID=$(printf "%03u" "${NEW_NUM}") Regards, David Bolt -- Team Acorn: http://www.distributed.net/ OGR-P2 @ ~100Mnodes RC5-72 @ ~15Mkeys SUSE 10.1 32 | | openSUSE 10.3 32b | openSUSE 11.0 32b | openSUSE 10.2 64b | openSUSE 10.3 64b | openSUSE 11.0 64b RISC OS 3.6 | TOS 4.02 | openSUSE 10.3 PPC | RISC OS 3.11 -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org