[SOLVED] nested for loop
by Drosera_capensis from LinuxQuestions.org on (#509F1)
Hello everyone,
I have a little issue with a nested for loop, and I don't understand what is not working in.
I try to output the following files:
title_one_1.txt
title_one_2.txt
title_one_3.txt
title_two_1.txt
title_two_2.txt
title_two_3.txt
title_three_1.txt
title_three_2.txt
title_three_3.txt
Therefore, I set up a nested for loop to output this list.
array="one two three"
for f in $array
do
for p in {1..3} ;
do
echo title_$f_$p.txt
done ;
done
But it is not working. It seems that variables as $f are not processed with underscores, but with dots.
Would anyone know how to output the list above?


I have a little issue with a nested for loop, and I don't understand what is not working in.
I try to output the following files:
title_one_1.txt
title_one_2.txt
title_one_3.txt
title_two_1.txt
title_two_2.txt
title_two_3.txt
title_three_1.txt
title_three_2.txt
title_three_3.txt
Therefore, I set up a nested for loop to output this list.
array="one two three"
for f in $array
do
for p in {1..3} ;
do
echo title_$f_$p.txt
done ;
done
But it is not working. It seems that variables as $f are not processed with underscores, but with dots.
Would anyone know how to output the list above?