LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-25-2009, 09:21 AM   #1
manya
Member
 
Registered: Apr 2004
Posts: 194

Rep: Reputation: 15
Need help in bash scripting in while loop


Hi Fellas,

Need your help in while loop, well I have endless while loop and accepting a resp from user and I need to jump out of the loop if I pass certain string and should not pass to next condition.

while :
do
echo "Enter Event :"
if [ -z "$resp" ] || [ $resp -eq "mailsend" ];then
echo "No Event number provided, exiting now"
mailsend ----------------> This is an another function that should get executed.
exit
else
ANSWER=`cat $EVENTDIR/$resp.html | grep -A4 "Characteristics and Indicators" | tail -n1 | awk '{print $NF}'`
echo $ANSWER
fi
 
Old 11-25-2009, 09:39 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Please put your code into [CODE] tags for better readability.

First, your loop needs to end with "done". e.g.:
Code:
while true; do
     stuff
     morestuff
done
To exit the loop based on some condition, you can use the "break" command.

If you don't have them already, head over to http://tldp.org and get the Bash Guide for Beginners, and the Advanced BASH Scripig Guide (ABS)
 
Old 11-25-2009, 09:51 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
break does what it says.

look at select and case in the bash manual.

even better, look at dialog or Xdialog
 
  


Reply



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
how to loop over text file lines within bash script for loop? johnpaulodonnell Linux - Newbie 9 07-28-2015 03:49 PM
bash scripting problem with nested if statements in while loop error xskycamefalling Programming 4 05-11-2009 03:14 PM
bash loop within a loop for mysql ops br8kwall Programming 10 04-30-2008 03:50 AM
bash scripting: loop over a file, replacing two decimal numbers frankie_DJ Programming 2 04-30-2007 04:04 PM
Linux scripting - wget loop northy_ie Programming 7 11-09-2005 08:17 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:55 PM.

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
Open Source Consulting | Domain Registration