A Counter That Stays at Zero
Why does count print 0 here?
count
0
count=0 cat hosts.txt | while read -r h; do count=$((count + 1)); done echo "$count"
Choose one answer
cat closes standard input before the loop has started reading from it.
cat
Arithmetic expansion doesn't work inside while loops.
while
The loop runs in a subshell, so it changes a copy.
read resets the variable at the end of the file.
read