Niels Janssen
Niels Janssen

Reputation: 189

bash script commands executed twice

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

Upvotes: 0

Views: 897

Answers (1)

choroba
choroba

Reputation: 241928

Underscore is a valid identifier character, therefore

subj$i_*.txt

is interpreted in bash as

subj${i_}*.txt

Which is not what you want. Separate the i from the underscore:

subj${i}_*.txt

or

subj$i\_*.txt

BTW, you can probably just call

awk -f met.awk subj{1..10}_*.txt

Upvotes: 3

Related Questions