variable scope in bash
From: e-doug (doug_at_forguson.com)
Date: 08/29/04
- Next message: Jack Klein: "Re: Connecting Intel 386EX to external device"
- Previous message: Patrick TJ McPhee: "Re: [Q] Text vs Binary Files"
- Next in thread: Paul Lutus: "Re: variable scope in bash"
- Reply: Paul Lutus: "Re: variable scope in bash"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 28 Aug 2004 23:38:54 -0400
redirecting the output from a loop seems to disrupt the scope of a variable
under bash.
#!/bin/bash
b=0
while [ $b -lt 10 ]
do
let "b++"
done
echo $b
produces the expecte dout of 10 - so far so good
now....
#!/bin/bash
b=0
while [ $b -lt 10 ]
do
let "b++"
done | sort
echo $b
results in the output of '0'
It acts as though the redirect causes a subshell where the local variable
isn't shared.
Comments?
- Next message: Jack Klein: "Re: Connecting Intel 386EX to external device"
- Previous message: Patrick TJ McPhee: "Re: [Q] Text vs Binary Files"
- Next in thread: Paul Lutus: "Re: variable scope in bash"
- Reply: Paul Lutus: "Re: variable scope in bash"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|