procmail
[Top] [All Lists]

Re: Fun With Shells (Part 2) (fwd)

1997-07-11 20:30:00
On Fri, 11 Jul 1997 you (Jim Irwin) wrote:
If you actually require that $N hold the string "055", use
"declare" rather than "let".

bash:~$ declare N=055
bash:~$ echo $N
055

Thanks for all that Jim.  Several folks here have pointed out that  
I misread the manual on the base10 business: the form, as you point  
out, is 10#063.

I start with a string that may lead with zero because this is  
derived from a filename that I want to ++.  So I need to coerce this  
string to an int, increment it, and coerce it back to a string.

Here, for completeness, is the "proof of concept" script, with  
acknowledgements to several here who helped with it.  You'll notice  
I've retained the kludge I did to workaround my misunderstanding of  
the base10 stuff -- it ain't so bad.

=================cut here================
#! /usr/gnu/bin/bash
# directories are nested thus (where <nnn> is a number of the
# form 004, and nb<nnn> is a file):
#  nbytes
#     #nb<nnn>
#        nb<nnn>

# find the highest numbered directory in nbytes
# and then find the highest numbered file in that
# directory, so we can create a new file in sequence.

NBDIR="/Net/NetWare/AST/JAMES_II/nbytes/"

HIGHEST=`ls -1 $NBDIR | tail -1`
LATEST=`ls -1 ${NBDIR}/${HIGHEST} | tail -1`
N=`echo $LATEST | cut -c 3-`

NN=1${N}
# assuming that $N always has three digits.
let NNN=NN-999

if [ $NNN -lt 10 ]
   then NNN="00${NNN}"
elif
   [ $NNN -lt 100 ]
   then NNN="0${NNN}"
fi

NEWEST="nb${NNN}"
echo $NEWEST
=================cut here================


el bid

<Prev in Thread] Current Thread [Next in Thread>