tru64-unix-managers (formerly alpha-osf-managers) (1994-2012)
 help / color / mirror / Atom feed
* SUMMARY: Bash while loop question
@ 2002-09-12 12:46 Jean-Pierre Vorlet
  0 siblings, 0 replies; only message in thread
From: Jean-Pierre Vorlet @ 2002-09-12 12:46 UTC (permalink / raw)
  Cc: Jean-Pierre.Vorlet

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-09-12 12:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-09-12 12:46 SUMMARY: 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