Strange shellscript behaviour?
From: Bjørn Augestad (boa_at_metasystems.no)
Date: 12/01/04
- Next message: Rich Teer: "Re: book programming in Unix"
- Previous message: obiru: "Re: join command"
- Next in thread: Måns Rullgård: "Re: Strange shellscript behaviour?"
- Reply: Måns Rullgård: "Re: Strange shellscript behaviour?"
- Reply: Rich Gibbs: "Re: Strange shellscript behaviour?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 01 Dec 2004 19:32:46 GMT
Below is a tiny example of a problem I ran into today. The script
contains two loops. Both loops reads lines from a file and modifies FOO.
For some strange reason FOO is reset to 1 after the first loop, but
keeps the value assigned(4) after the second loop.
Is this a bug or am I missing something obvious?
TIA
Bjørn
PS: This is GNU bash, version 2.05b.0(1)-release
#!/bin/bash
FOO=1
cat ~/.bashrc | while read line; do
FOO=2
done
echo $FOO # Here foo is 1
FOO=3
while read line; do
FOO=4
done < ~/.bashrc
echo $FOO # But here it is 4
- Next message: Rich Teer: "Re: book programming in Unix"
- Previous message: obiru: "Re: join command"
- Next in thread: Måns Rullgård: "Re: Strange shellscript behaviour?"
- Reply: Måns Rullgård: "Re: Strange shellscript behaviour?"
- Reply: Rich Gibbs: "Re: Strange shellscript behaviour?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|