Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 08-22-2013, 08:16 PM   #1
LQ Newbie
Registered: Aug 2013
Posts: 3

Rep: Reputation: Disabled
Talking Need Help with a "while" loop


I need some help with looping. I need a portion of a script where I ask for two numbers to be entered, which also continue to ("while") loop until "q" is pressed to quit the loop.

The numbers are ultimately added, but what I am looking for is that I need the two numbers that are entered to be looped.

Here is my present script (below) which adds two numbers. Please be gentle as I am truly "a newbie."

Thank You,


echo "Enter one number"
read num1
echo “Enter another number”
read num2
sum=$((num1 + num2))
echo "The sum is = $sum"
Old 08-22-2013, 08:49 PM   #2
Registered: Aug 2009
Location: Bangaluru, India
Distribution: CentOS 6.5, SuSE SLED/ SLES 10.2 SP2 /11.2, Fedora 11/16
Posts: 664

Rep: Reputation: 81
you did'nt mentioned how the no's are looped, so considering this is not your school assignment, let me give you a usage of while loop so you try looping your variables the way you want them and let us know where you stuck.

while [condition] 
[statements to be looped]
although i cant see any good use of looping two variables in a loop just for adding them instead sounds like a home assignment.

Old 08-23-2013, 12:47 AM   #3
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 764
Blog Entries: 3

Rep: Reputation: 366Reputation: 366Reputation: 366Reputation: 366
Like SAbhi wrote above, it's not really clear what you are trying to achieve here. I honestly don't understand your question, specifically:
The numbers are ultimately added, but what I am looking for is that I need the two numbers that are entered to be looped
How? Why?

Best of luck, and get back with more info, then we might be able to help out.



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
[SOLVED] Recursively naming files in a directory after processing them in a "for" loop geodave0110 Programming 6 11-14-2011 12:06 PM
[SOLVED] "while read line" doesn't work with ssh in the loop body asemaany Programming 5 03-28-2010 01:14 AM
Elements in a "for loop" using bash not being separated by white spaces. ralste Programming 6 11-10-2009 02:26 AM
"Permission denied" and "recursive directory loop" when searching for string in files mack1e Linux - Newbie 5 06-12-2008 07:38 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:08 PM.

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