I have code like this:
#!/bin/bash
n=0
for file in *.txt
do
tail -c1 $file | read -r _ || (
((n++))
echo "$file is missing a final newline, issue #$n"
)
done
But when I run it, the numbers aren't incrementing:
a.txt is missing a final newline, issue #1
b.txt is missing a final newline, issue #1
How can I fix this? It looks like a scope issue, since the 0 is incremented to 1 as though the previous increment was ignored.
tail -c1 "$file".