Bash Scripting Variable Scope Using Piped While Loop -
Bash Scripting Variable Scope Using Piped While Loop
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
(( ++counter ))
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