[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
BASH variable scope inside while loop and SHLVL (Re: FAQ E4)
From: |
Kevin R. Bulgrien |
Subject: |
BASH variable scope inside while loop and SHLVL (Re: FAQ E4) |
Date: |
Tue, 29 May 2001 14:12:07 -0500 |
From: http://mail.gnu.org/pipermail/bug-bash/2000-August/001026.html
> Scope of variable in shell script
>
> Chet Ramey chet@po.cwru.edu
> Thu, 31 Aug 2000 15:31:17 -0400
>
> Previous message: Scope of variable in shell script
> Next message: Bug in getopts builtin.
> Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
>
>> uname output: Linux pckvc 2.2.14-5.0 #1 Tue Mar 7 21:07:39 EST 2000 i686
>>
>> Bash Version: 1.14
>> Patch Level: 7
>>
>> Description:
>>
>> Scope of variable "counter" in following constructions seems wrong.
>
> The while loop is run in a subshell because of the pipeline. A subshell
> cannot affect its parent's environemnt. Read the Bash FAQ, question E4,
> for more details.
I have read the FAQ, and understand the concept, however, consider the
following shell transcript:
$ bash --version
GNU bash, version 2.04.11(1)-release (i386-redhat-linux-gnu)
Copyright 1999 Free Software Foundation, Inc.
$cat myscript
echo $SHLVL
echo "-"
echo | while read var
do
echo $SHLVL
done
echo "-"
echo $SHLVL
$bash myscript
2
-
2
-
2
$
Given your explanation and reference to FAQ E4, should this script
not return:
2
-
3
-
2
> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
> ( ``Discere est Dolere'' -- chet)
>
> Chet Ramey, CWRU chet@po.CWRU.Edu http://cnswww.cns.cwru.edu/~chet/
>
--
Kevin R. Bulgrien, Engineer
Mailto:kbulgrien@vcsd.com
Vertex RSI, A TriPoint Global Company http://www.vcsd.com/
Controls & Structures Division
1915 Harrison Road Tel: 903-295-1480 x288
Longview, TX 75604-5438 Fax: 903-295-1479
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- BASH variable scope inside while loop and SHLVL (Re: FAQ E4),
Kevin R. Bulgrien <=