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: Bash while loop question Date: Thu, 12 Sep 2002 09:55:49 +0000 (MET_DST) Sender: tru64-unix-managers-owner@ornl.gov Message-ID: <00A13DCB.099843B6.1@UFPER6.UNIFR.CH> NNTP-Posting-Host: localhost.gmane.org X-Trace: main.gmane.org 1031817381 22704 127.0.0.1 (12 Sep 2002 07:56:21 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Thu, 12 Sep 2002 07:56:21 +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 17pOpn-0005u2-00 for ; Thu, 12 Sep 2002 09:56:19 +0200 Original-Received: (qmail 22627 invoked by uid 5); 12 Sep 2002 07:56:23 -0000 Original-Followup-To: poster Precedence: bulk Original-Received: (qmail 22618 invoked by uid 49493); 12 Sep 2002 07:56:23 -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.425738 secs); 12 Sep 2002 07:56:23 -0000 Original-Received: from unknown (HELO emroute1.cind.ornl.gov) (160.91.4.119) by 0 with SMTP; 12 Sep 2002 07:56:22 -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 <0H2B004CBFDX6P@emroute1.cind.ornl.gov> for tru64-unix-managers@sws1.ctd.ornl.gov (ORCPT tru64-unix-managers@ornl.gov) ; Thu, 12 Sep 2002 03:56:22 -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 <0H2B0095KFD53F@emroute1.cind.ornl.gov> for tru64-unix-managers@sws1.ctd.ornl.gov (ORCPT tru64-unix-managers@ornl.gov) ; Thu, 12 Sep 2002 03:55:53 -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 17pOpM-0001Rz-00 for tru64-unix-managers@ornl.gov; Thu, 12 Sep 2002 09:55:52 +0200 Original-Received: from ufper7.unifr.ch ([134.21.14.67]) by siufuxsun04.unifr.ch with smtp (Exim 3.22 #4) id 17pOpK-0001Rx-00; Thu, 12 Sep 2002 09:55:50 +0200 Original-Received: by UFPER6.UNIFR.CH (MX V4.2 AXP) id 1; Thu, 12 Sep 2002 09:55:50 +0000 (MET_DST) Original-To: tru64-unix-managers@ornl.gov Xref: main.gmane.org gmane.os.tru64.managers:1657 X-Report-Spam: http://spam.gmane.org/gmane.os.tru64.managers:1657 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