From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Jean-Pierre Vorlet Newsgroups: gmane.os.tru64.managers Subject: SUMMARY: Bash while loop question Date: Thu, 12 Sep 2002 12:46:19 +0000 (MET_DST) Sender: tru64-unix-managers-owner@ornl.gov Message-ID: <00A13DE2.DAC22175.1@UFPER6.UNIFR.CH> NNTP-Posting-Host: localhost.gmane.org X-Trace: main.gmane.org 1031827605 16415 127.0.0.1 (12 Sep 2002 10:46:45 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Thu, 12 Sep 2002 10:46:45 +0000 (UTC) Cc: Jean-Pierre.Vorlet@unifr.ch Return-path: Original-Received: from sws1.ctd.ornl.gov ([160.91.20.101]) by main.gmane.org with smtp (Exim 3.35 #1 (Debian)) id 17pRUf-0004GN-00 for ; Thu, 12 Sep 2002 12:46:41 +0200 Original-Received: (qmail 29552 invoked by uid 5); 12 Sep 2002 10:46:38 -0000 Original-Followup-To: poster Precedence: bulk Original-Received: (qmail 29543 invoked by uid 49493); 12 Sep 2002 10:46:38 -0000 Original-Received: from jean-pierre.vorlet@unifr.ch by sws1 by uid 49491 with qmail-scanner-1.14 (clamscan: 0.24. Clear:. Processed in 0.415659 secs); 12 Sep 2002 10:46:38 -0000 Original-Received: from unknown (HELO emroute1.cind.ornl.gov) (160.91.4.119) by 0 with SMTP; 12 Sep 2002 10:46:38 -0000 Original-Received: from emroute1.cind.ornl.gov (localhost [127.0.0.1]) by emroute1.cind.ornl.gov (PMDF V6.1-1 #39060) with ESMTP id <0H2B00C26N9PQW@emroute1.cind.ornl.gov> for tru64-unix-managers@sws1.ctd.ornl.gov (ORCPT tru64-unix-managers@ornl.gov) ; Thu, 12 Sep 2002 06:46:37 -0400 (EDT) Original-Received: from siufuxsun04.unifr.ch (siufuxsun04.unifr.ch [134.21.13.54]) by emroute1.cind.ornl.gov (PMDF V6.1-1 #39060) with ESMTP id <0H2B00L9MN9KTR@emroute1.cind.ornl.gov> for tru64-unix-managers@sws1.ctd.ornl.gov (ORCPT tru64-unix-managers@ornl.gov) ; Thu, 12 Sep 2002 06:46:33 -0400 (EDT) Original-Received: from localhost ([127.0.0.1] helo=siufuxsun04.unifr.ch) by siufuxsun04.unifr.ch with esmtp (Exim 3.22 #3) id 17pRUL-0002T1-00 for tru64-unix-managers@ornl.gov; Thu, 12 Sep 2002 12:46:21 +0200 Original-Received: from ufper7.unifr.ch ([134.21.14.67]) by siufuxsun04.unifr.ch with smtp (Exim 3.22 #4) id 17pRUK-0002Sz-00; Thu, 12 Sep 2002 12:46:20 +0200 Original-Received: by UFPER6.UNIFR.CH (MX V4.2 AXP) id 1; Thu, 12 Sep 2002 12:46:19 +0000 (MET_DST) Original-To: tru64-unix-managers@ornl.gov Xref: main.gmane.org gmane.os.tru64.managers:1659 X-Report-Spam: http://spam.gmane.org/gmane.os.tru64.managers:1659 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