(not sure if there is a more appropriate forum for discussions on scripting, are there?)
On Mon, 16 Dec 2002, Ashley M. Kirchner wrote: > for fs in root etc boot yp mysql apache mail home ; do > # LOOP through the 13 (latest) days of the backup > for ((idx=13 ; idx >= 2; idx--)) ; do > # create next ($nidx) and a var for $pidx (padded $idx) > # for some reason if I just use $idx (instead of $pidx, it fails) > nidx=$((idx+1)); > pidx=$idx; > # see if either $pidx or $nidx needs padding > if [ "$nidx" -lt "10" ] ; then > nidx=0$nidx; > fi > if [ "$pidx" -lt "10" ] ; then > pidx=0$pidx; > fi if you want to do leading zero-padding, you're waaaaaay better off writing a quick function and putting it at the top of the script. off the top of my head, here's one that can left pad an arbitrary value with zeroes to any length you want: function padzeroes { ZEROES="0000000000" # hack, choke :-) ARGLEN=$(expr length $1) DESIREDLEN=$2 PAD=$(expr substr "0000000000" 1 $((DESIREDLEN - ARGLEN))) echo "$PAD$1" } you would call it for some variable $i as: i=$(padzeroes $i 5) to left-pad the value out to length 5. rday p.s. i thought there was an even easier way to do this, but sadly, i was remembering typed variables from the korn shell. bash apparently doesn't have typed variables that would pad automatically. -- redhat-list mailing list unsubscribe mailto:[EMAIL PROTECTED]?subject=unsubscribe https://listman.redhat.com/mailman/listinfo/redhat-list