LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 08-22-2013, 09:16 PM   #1
jefferj54
LQ Newbie
 
Registered: Aug 2013
Posts: 3

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


Hi,

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,

joe.


echo "Enter one number"
read num1
echo “Enter another number”
read num2
sum=$((num1 + num2))
echo "The sum is = $sum"
 
Old 08-22-2013, 09:49 PM   #2
SAbhi
Member
 
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: 80
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.

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

cheers
 
Old 08-23-2013, 01:47 AM   #3
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Xubuntu, Manjaro
Posts: 745
Blog Entries: 3

Rep: Reputation: 347Reputation: 347Reputation: 347Reputation: 347
Like SAbhi wrote above, it's not really clear what you are trying to achieve here. I honestly don't understand your question, specifically:
Quote:
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.

HMW
 
  


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


All times are GMT -5. The time now is 10:42 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration