From: Jean-Pierre Vorlet (Jean-Pierre.Vorlet@unifr.ch)
Date: Thu Sep 12 2002 - 08:46:19 EDT
As expected for this list, fast and precise reply from Julien Soula
(soula@lifl.fr) !
The "while" loop is executed in a child process and all variables
are lost at the end of the loop. Bellow, the same script to read
lines from a file with correction and improvement.
Tanks again, Julien !
------------------------------------------------------------------
#!/bin/bash
#----------> Enhanced
#
TMPFILE="RPM.lst"
declare -i RPMCNT=0 # Array index
declare -a RPMLIST # Array for RPM list
#
rpm -qa > $TMPFILE
#
while read LINE
do
let RPMCNT=RPMCNT+1 # Update index
RPMLIST[$RPMCNT]=$LINE # Update array
printf "%4i %4i %-s\n" $RPMCNT ${#RPMLIST[*]} \
${RPMLIST[$RPMCNT]}
done < $TMPFILE
#
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
This archive was generated by hypermail 2.1.7 : Sat Apr 12 2008 - 10:48:52 EDT