bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Perhaps variables are re-initialized after a while loop


From: fred
Subject: Perhaps variables are re-initialized after a while loop
Date: Tue, 26 Dec 2000 22:58:09 +0100

Configuration Information [Automatically generated, do not change]:
Machine: i386
OS: linux
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i386' 
-DCONF_OSTYPE='linux' -DCONF_MACHTYPE='i386-suse-linux' -DCONF_VENDOR='suse' 
-DSHELL -DHAVE_CONFIG_H  -D_FILE_OFFSET_BITS=64  -I. -I/usr/include -I. -I./lib 
-I/usr/include -O2 -m486 -D_GNU_SOURCE -Wall -pipe
uname output: Linux servans 2.2.14 #1 Sat Mar 25 00:45:35 GMT 2000 i586 unknown
Machine Type: i386-suse-linux

Bash Version: 2.03
Patch Level: 0
Release Status: release

Description:
        In the example below I have initialized a variable LINENUMBER
        with the value zero. Then I enter a loop to process a number
        of lines. In the loop the variable LINENUMBER is output.
        After the end of the loop the variable is reset to the initial
        value.

        Perhaps I have overlooked something (although I did spent much
        time to resolve the problem).

Repeat-By:
        The script (named x) I use to demonstrate the problem :

#!/bin/bash
 let LINENUMBER=0
 egrep -v  "^#|^ *$"  $1                                        |     \
 (while read  LINE  REST
 do
     let LINENUMBER=$LINENUMBER+1
     echo "$LINENUMBER   $LINE   $REST"
 done )
 echo "Total numbers of line : $LINENUMBER"
 exit 0

        The command to show the problem :

bash -v x /etc/resolv.conf

        The output I get on the screen :

#!/bin/bash
 let LINENUMBER=0
 egrep -v  "^#|^ *$"  $1                                        |     \
 (while read  LINE  REST
 do
     let LINENUMBER=$LINENUMBER+1
     echo "$LINENUMBER   $LINE   $REST"
 done )
1   domain   mobach.nl
2   search   mobach.nl mobach.com
3   nameserver   172.16.21.73
4   nameserver   172.16.21.12
5   nameserver   172.16.21`39
6   nameserver   172.16.21.210
 echo "Total numbers of line : $LINENUMBER"
Total numbers of line : 0
 exit 0

Fix:
        Sorry, I don't master the bash sources. I'm not a C programmer also :-(.

Regards,

Fred



reply via email to

[Prev in Thread] Current Thread [Next in Thread]