Bash – using variables outside a while loop 2
The bash runs every loop (while or for) in a subshell. The values for a variable defined inside such a loop / subshell are not available outside. #!/bin/bash t=0 while read line; do t=$(( t + 1 )) done < /etc/passwd echo $t Returns 0 for $t but inside the […]