Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what's wrong with this simple bash command?

Tags:

linux

bash

$i is not working... it's making me crazy!

for i in {1..200}; 
do echo "/scratch/inputTest/prob/timit.test.pg.list_10_$i_prob.bin" >> longProbList; 
done

in the file there is just

/scratch/inputTest/prob/timit.test.pg.list_10_.bin
/scratch/inputTest/prob/timit.test.pg.list_10_.bin
/scratch/inputTest/prob/timit.test.pg.list_10_.bin
/scratch/inputTest/prob/timit.test.pg.list_10_.bin
/scratch/inputTest/prob/timit.test.pg.list_10_.bin
/scratch/inputTest/prob/timit.test.pg.list_10_.bin
/scratch/inputTest/prob/timit.test.pg.list_10_.bin
/scratch/inputTest/prob/timit.test.pg.list_10_.bin
/scratch/inputTest/prob/timit.test.pg.list_10_.bin
/scratch/inputTest/prob/timit.test.pg.list_10_.bin
/scratch/inputTest/prob/timit.test.pg.list_10_.bin
/scratch/inputTest/prob/timit.test.pg.list_10_.bin
/scratch/inputTest/prob/timit.test.pg.list_10_.bin
/scratch/inputTest/prob/timit.test.pg.list_10_.bin
/scratch/inputTest/prob/timit.test.pg.list_10_.bin
/scratch/inputTest/prob/timit.test.pg.list_10_.bin
/scratch/inputTest/prob/timit.test.pg.list_10_.bin
like image 277
Kiarash Avatar asked Feb 23 '23 07:02

Kiarash


2 Answers

It thinks your variable name is $i_prob since an underscore is a valid character for a variable name. Use ${i} to fix this:

for i in {1..200}; 
do echo "/scratch/inputTest/prob/timit.test.pg.list_10_${i}_prob.bin" >> longProbList; 
done
like image 158
John Kugelman Avatar answered Feb 26 '23 21:02

John Kugelman


You've forgotten the " " around $i

for i in {1..200}; 
do echo "/scratch/inputTest/prob/timit.test.pg.list_10_"$i"_prob.bin" >> longProbList; 
done
like image 28
therealmarv Avatar answered Feb 26 '23 20:02

therealmarv