----- Original Message -----
From: "Randall R Schulz"
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,
Your cut command looks like it's going to give you "/etc/apache2/sites" every time. You should sort your result because ls garantees no particular order unless using ie -lt which is time anyways not numerical. You don't need expr as long as you are using bash or ksh or zsh or almost anything but stock sh on sco unix or solaris. #!/bin/bash unalias ls ## grr F*&^* distros... A=`cd /etc/apache2/sites-enabled ;ls |cut -d- -f1 |sort -n |tail -1` A=`printf "%03i\n" $((++A))` In ksh you don't need to spawn a sub shell just to use printf just to get it back to right-justifid, zero-padded, 3 digits. Nor do you need the subshell nor any of the processes in the backticks with ls either as long as we're making any assumptions about the filenames anyways. There is a quirk that you must start with 001 though. You can have a file 000-site0, and other files of other forms, just this script will never see those. #!/bin/ksh typeset -Z3 A=001 cd /etc/apache2/sites-enabled while [ -e ${A}-* ] ;do ((++A)) ;done In both cases $A holds the new/next value at the end echo Next site is $A -- Brian K. White brian@aljex.com http://www.myspace.com/KEYofR +++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++. filePro BBx Linux SCO FreeBSD #callahans Satriani Filk! -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org