Could someone please explain to me why my while loop seems to have an internal scope? I've seen multiple explanations online but they all have to do with pipes. My code has none.
#!/bin/sh while read line do echo "File contents: $line" echo if [ 1=1 ]; then test1=bob fi echo "While scope:" echo " test1: $test1" done < test.txt if [ 1=1 ]; then test2=test2; fi echo; echo "Script scope: " echo " test1: $test1" echo " test2: $test2"
File contents: In the file While scope: test1: bob Script scope: test1: test2: test2