From: Jean-Pierre Vorlet <Jean-Pierre.Vorlet@unifr.ch>
Cc: Jean-Pierre.Vorlet@unifr.ch
Subject: Bash while loop question
Date: Thu, 12 Sep 2002 09:55:49 +0000 (MET_DST) [thread overview]
Message-ID: <00A13DCB.099843B6.1@UFPER6.UNIFR.CH> (raw)
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
reply other threads:[~2002-09-12 9:55 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox