You're running into a variable scope issue. The variables defined in the while loop have their own local scope context, and changes to the variable will not be seen outside of the loop. The while loop is essentially a subshell which gets a COPY of the shell environment, and any changes to the environment are lost at the end of the shell. See this StackOverflow question.
jsbillings
- 24.9k
- 7
- 58
- 58