I may be on crack here, but am I missing something about variable scoping here? Observe this simple script:
BOOBOO="blah"
echo $BOOBOO
ls | while read LINE; do
BOOBOO="moo"
echo $BOOBOO
done
echo "Final: $BOOBOO"
The 'ls' is just my excuse to get some kind of multiline input. Anyway, one would expect the global variable $BOOBOO to be changed to "moo" at the end, but instead, it remains "blah" (yet "moo" gets echoed for each line output by ls). I think this has to do with the while loop being part of the child process for ls, which makes sense (since if i take off the "ls |" and call it from the command line with "ls | script", it works fine).
I DO NOT want to have to do this (that is, I want to call ls from within the script). How do I do this without messing up the variables? I was thinking:
LS=`ls -1`
but that still stores it as ONE line, and I really want it as several.
Thanks
BOOBOO="blah"
echo $BOOBOO
ls | while read LINE; do
BOOBOO="moo"
echo $BOOBOO
done
echo "Final: $BOOBOO"
The 'ls' is just my excuse to get some kind of multiline input. Anyway, one would expect the global variable $BOOBOO to be changed to "moo" at the end, but instead, it remains "blah" (yet "moo" gets echoed for each line output by ls). I think this has to do with the while loop being part of the child process for ls, which makes sense (since if i take off the "ls |" and call it from the command line with "ls | script", it works fine).
I DO NOT want to have to do this (that is, I want to call ls from within the script). How do I do this without messing up the variables? I was thinking:
LS=`ls -1`
but that still stores it as ONE line, and I really want it as several.
Thanks