这个简单的bash命令有什么问题?

时间:2011-08-13 01:29:15

标签: linux bash

$我不工作......这让我发疯了!

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

在文件中只有

/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

2 个答案:

答案 0 :(得分:7)

它认为您的变量名称为$i_prob,因为下划线是变量名称的有效字符。使用${i}来解决此问题:

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

答案 1 :(得分:1)

你已经忘记了$ i周围的“”

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