LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 03-31-2009, 08:12 AM   #1
icecubeflower
Member
 
Registered: Mar 2008
Location: USA
Distribution: Slackware 13.1
Posts: 304

Rep: Reputation: 33
shell script question $variable in loop


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!"
 
Old 03-31-2009, 08:16 AM   #2
icecubeflower
Member
 
Registered: Mar 2008
Location: USA
Distribution: Slackware 13.1
Posts: 304

Original Poster
Rep: Reputation: 33
Oh wait, I just put "" around i. That works.
 
Old 03-31-2009, 09:09 AM   #3
icecubeflower
Member
 
Registered: Mar 2008
Location: USA
Distribution: Slackware 13.1
Posts: 304

Original Poster
Rep: Reputation: 33
I'd like to delete this thread to keep from wasting anyone's time but I don't see that option.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script , while loop ykc Programming 5 03-30-2009 07:50 AM
Shell Script skipping a loop dnvikram Programming 2 01-23-2009 02:29 PM
Loop in Shell Script delamatrix Programming 4 07-24-2008 05:20 PM
Shell variable in Linux is reset after while loop CBenner Programming 7 05-19-2006 09:46 AM
Shell-script question about getting a number as a variable stormrider_may Programming 9 03-14-2006 08:18 AM


All times are GMT -5. The time now is 12:33 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration