tru64-unix-managers (formerly alpha-osf-managers) (1994-2012)
 help / color / mirror / Atom feed
From: Jean-Pierre Vorlet <Jean-Pierre.Vorlet@unifr.ch>
Cc: Jean-Pierre.Vorlet@unifr.ch
Subject: SUMMARY: Bash while loop question
Date: Thu, 12 Sep 2002 12:46:19 +0000 (MET_DST)	[thread overview]
Message-ID: <00A13DE2.DAC22175.1@UFPER6.UNIFR.CH> (raw)

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


                 reply	other threads:[~2002-09-12 12:46 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