On Mon, 18 Aug 2008, Nick Zeljkovic wrote:-
And these can be reduced to one line:
FID=$(printf "%03u" "${NEW_NUM}")
Thanks! I was missing that, seems to have done the trick replacing my checks, but something funky is going on there with numbers like 010 or anything starting with one zero: root@sgd1 [~/bin]# NEWNUM="015" root@sgd1 [~/bin]# echo $NEWNUM 015 root@sgd1 [~/bin]# printf "%03u" "${NEWNUM}" 013
Any ideas ?
That's bash treating the number as octal and converting it to base 10 for you. The only way to get printf to produce a decimal number is to strip off the leading 0's. And going back, you don't really need to use the "sed" command. This should do the trick: # no need for the pipe into cut # CURNUM=$(ls /etc/apache2/sites-enables|tail -1) # force use of base 10, and strip off everything from the first - # NEWNUM=$(( 10#${CURNUM%%-*} + 1 )) # get the length of $NEWNUM, if still required # NUMLEN=${#NEWNUM} # and create a 3-digit number with leading 0's # FID=$(printf "%03u" "${NEWNUM}" 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