I'm running a command that writes warnings to stdout, and I want my script to stop on those warnings, so piecing together a lot of stuff I learned here, I have the following...
warnd=false;
myLongCommand |
while IFS= read -r line
do
if [[ $line == *"WARNING in ."* ]]; then
warnd=true;
echo "found a warning!!!!!"
break
fi
echo $line
done
echo WARNING IS $warnd
if [[ "$warnd" == true ]]; then
echo "exiting due to warning"
exit
else
echo "no warnings"
fi
But this doesn't work as I expect. When myLongCommand writes a warning, I see the following echo'd...
found a warning!!!!!
WARNING IS false
no warnings
Why isn't the change to my warnd
variable seen after the loop. I've read about scoping of shell script variables, but nothing seems to indicate that the variable inside the loop has a different scope.