I am trying to run a simple bash script that runs through folders named subj1, subj2, etc. and executes an awk script in each folder. The problem is that the awk command is executed twice, even though it is only listed once in the script. I just started using bash and I am not sure I understand what is happening here. Any help is appreciated.
for i in `seq 1 10`;
do
cd subj$i
awk -f ../melt.awk subj$i_*.txt
cd ..
done
subj$i_*.txtshould besubj${i}_*.txt. Otherwise, it's looking for a variable named$i_, which doesn't exist.set -xbefore the loop, so it will display all the commands as they're being executed.seqisn't a POSIX-standard command, so scripts relying on it are needlessly unportable (and also slower, since running it involves spawning a subprocess).for ((i=1; i<10; i++))is the terse version using only bash built-in functionality.