I can't figure out variables in loops. If you look at this block of code below, I understand that one. The loop runs 5 times and substitutes 1,2,3,4,5 for $i:
Code:
for i in 1 2 3 4 5
do
echo "Welcome $i times"
done
output:
Code:
icecube@inferno:~/shellscripts$ sh colortext.sh
Welcome 1 times
Welcome 2 times
Welcome 3 times
Welcome 4 times
Welcome 5 times
icecube@inferno:~/shellscripts$
But now I want to output a string in several times in different colors. I try this:
Code:
for i in 30 31 32 33 34 35 36 37
do
echo -e "\033[$im Hello Colorful World!"
done
That doesn't work. It thinks im is a variable.
I try this:
Code:
for i in 30 31 32 33 34 35 36 37
do
echo -e "\033[$i m Hello Colorful World!"
done
That doesn't work, either. Basically I want to make this series of commands using a variable and a loop but I can't figure out how to do it, I don't know the syntax:
echo -e "\033[$30m Hello Colorful World!"
echo -e "\033[$31m Hello Colorful World!"
echo -e "\033[$32m Hello Colorful World!"
echo -e "\033[$33m Hello Colorful World!"
echo -e "\033[$34m Hello Colorful World!"
echo -e "\033[$35m Hello Colorful World!"
echo -e "\033[$36m Hello Colorful World!"
echo -e "\033[$37m Hello Colorful World!"