* Bash while loop question
@ 2002-09-12 9:55 Jean-Pierre Vorlet
0 siblings, 0 replies; only message in thread
From: Jean-Pierre Vorlet @ 2002-09-12 9:55 UTC (permalink / raw)
Cc: Jean-Pierre.Vorlet
This is not a Tru64 specific question, but bash should be widely
used under this OS!
I would like to count and compare the list of RMP between two nodes.
The bash script below (a short test script), create the list, read
it into an array and count the number of lines.
The strange thing appear at the end of the ?while? loop, the last
?printf? command always display 0 for index value!
But, inside the loop, index and RMP name are correctly displayed!
My question:
Why array data and index are lost at the end of the loop?
Any help will be greatly appreciated.
------------------------------------------------------------------
#!/bin/bash
#----------> For test only
#
TMPFILE="RPM.lst"
declare -i RPMCNT=0 # Array index
declare -a RPMLIST # Array for RPM list
#
rpm -qa > $TMPFILE
#
cat < $TMPFILE | while true
do
read LINE
if [ "X$LINE" = "X" ]; then break; fi # Empty line !
let RPMCNT=RPMCNT+1 # Update index
RPMLIST[$RPMCNT]=$LINE # Update array
printf "%4i %4i %-s\n" $RPMCNT ${#RPMLIST[*]} \
${RPMLIST[$RPMCNT]}
done
#
printf "\nRPM count: %4i %4i\n" $RPMCNT ${#RPMLIST[*]}
if [ -f $TMPFILE ]; then rm -f $TMPFILE; fi
exit 0
------------------------------------------------------------------
Jean-Pierre Vorlet Jean-Pierre.Vorlet@unifr.ch +41 26 300 7218
System Manager University of Fribourg Switzerland
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2002-09-12 9:55 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-09-12 9:55 Bash while loop question Jean-Pierre Vorlet
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox