I've been struggling with this for awhile, wondering why all of my variables are null. I just realized the variables disappear after leaving this while loop.
Note that I'm piping to the while loop which makes a subshell I believe which is the cause of the issue:
echo "$accounts"|while read thisline; do
somevariable="some value"
(( ++counter ))
done
At all costs you need to avoid the style above, use a for loop or whatever it takes BUT DO NOT pipe anything in or the variables you get from the loop will be NULL
bash, scripting, variable, scope, piped, loopi, ve, struggling, variables, null, piping, subshell, echo, quot, thisline, somevariable,