LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 05-13-2010, 01:44 PM   #1
K_REY_C
LQ Newbie
 
Registered: May 2010
Distribution: Fedora, Debian
Posts: 14

Rep: Reputation: 0
Bash Script Problem - Stops after While loop


Totally new to programming (as of this morning) so please bear with me (thanks!)

I have a bash script that stops working after the first while loop.

#part 1
While
do
This
That
The Other
done

#part 2
While
do
MOre
More
More
done

Every arguement above the first loop completes (including the first loop itself) but anything below (incuding the second while loop) doesn't finish.

I know that it isn't a problem with an unending loop... it seems to be something about the While loop that I'm not understanding... but I can't figure it out. I just need arguments below the first while loop to take place.

Any help appreciated. Thanks.
 
Old 05-13-2010, 01:54 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Welcome to LQ!!

I think you may need to post your actual code....

Also, try putting in a simple echo statement right after the first loop (to confirm that you are in fact exiting the loop)
 
1 members found this post helpful.
Old 05-13-2010, 02:01 PM   #3
yooy
Senior Member
 
Registered: Dec 2009
Posts: 1,387

Rep: Reputation: 174Reputation: 174
while loop need arguments

you can exit while loop with "exit"
 
1 members found this post helpful.
Old 05-13-2010, 02:04 PM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by yooy View Post
you can exit while loop with "exit"
exit will exit the script; to exit a loop use break.
 
1 members found this post helpful.
Old 05-13-2010, 02:14 PM   #5
K_REY_C
LQ Newbie
 
Registered: May 2010
Distribution: Fedora, Debian
Posts: 14

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by pixellany View Post
Welcome to LQ!!
Thanks for the welcome.

The script is able to output "#WHILE MALE CHARACTERS" but doesn't do anything below.

Thanks!

KYLE

Quote:
#! /bin/bash

#User Input - Defines number within each category
FEMALEinput=$(zenity --width 500 --height 100 --entry --title "Manual Input" --text "How Many Women?" --entry-text "1 - ?")

MALEinput=$(zenity --width 500 --height 100 --entry --title "Manual Input" --text "How Many Men?" --entry-text "1 - ?")

CHARACTERS=$(($MALEinput + $FEMALEinput))

LOCATIONinput=$(zenity --width 500 --height 100 --entry --title "Manual Input" --text "How Many LOCATIONS?" --entry-text "1 - infinity")

#Create New File
touch /home/kyconway/`date +%Y-%B-%d`.ScriptStart
NEWFILE=/home/kyconway/`date +%Y-%B-%d`.ScriptStart

#Insert Separation
echo __________________________________________________ >> $NEWFILE
#Today's Date
date >> $NEWFILE
#Insert Separation
echo __________________________________________________ >> $NEWFILE
#Inserts Blank Line
echo $BLANKLINE >> $NEWFILE

#Insert Title of Category 2
echo [LOCATION] >> $NEWFILE
#Random Selection from Character file to new file
shuf -n $LOCATIONinput /home/kyconway/Desktop/LOCATION.txt >> $NEWFILE
#Inserts Blank Line
echo $BLANKLINE >> $NEWFILE

#Insert Title of Category 3
echo [CRIME] >> $NEWFILE
#Random Selection from Character file to new file
shuf -n 1 /home/kyconway/Desktop/CRIME.txt >> $NEWFILE

#Inserts Blank Line
echo $BLANKLINE >> $NEWFILE

echo [CHARACTERS] >> $NEWFILE

#WHILE MALE CHARACTERS
myvar1=0
while [ $myvar1 -ne $MALEinput ]
do
shuf -n 1 /home/kyconway/Desktop/FIRSTNAME-M.txt >> $NEWFILE
shuf -n 1 /home/kyconway/Desktop/SURNAME.txt >> $NEWFILE
shuf -n 1 /home/kyconway/Desktop/OCCUPATIONS.txt >> $NEWFILE
echo $BLANKLINE >> $NEWFILE
myvar1=$(( $myvar1 + 1 ))
done

#WHILE FEMALE CHARACTERS
myvar2=0
while [ $myvar2 -ne $FEMALEinput ]
shuf -n 1 /home/kyconway/Desktop/FIRSTNAME-F.txt >> $NEWFILE
shuf -n 1 /home/kyconway/Desktop/SURNAME.txt >> $NEWFILE
shuf -n 1 /home/kyconway/Desktop/OCCUPATIONS.txt >> $NEWFILE
echo $BLANKLINE >> $NEWFILE
myvar2=$(( $myvar2 + 1 ))
done

#Visual Notification of New File
notify-send -i /home/kyconway/playidea.png "New Start!!!"

#Open New File
/usr/bin/gedit $NEWFILE
 
Old 05-13-2010, 02:32 PM   #6
yooy
Senior Member
 
Registered: Dec 2009
Posts: 1,387

Rep: Reputation: 174Reputation: 174
your second while loop lacks "do"

Last edited by yooy; 05-13-2010 at 02:37 PM.
 
1 members found this post helpful.
Old 05-13-2010, 02:42 PM   #7
K_REY_C
LQ Newbie
 
Registered: May 2010
Distribution: Fedora, Debian
Posts: 14

Original Poster
Rep: Reputation: 0
Thanks yooy!

Of course it was an easy answer!

Thanks all for help and quick responses!

KYLE
 
Old 05-13-2010, 06:59 PM   #8
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,999

Rep: Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190
Please mark as SOLVED once you have your answer
 
1 members found this post helpful.
  


Reply

Tags
bash scripting


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
how to loop over text file lines within bash script for loop? johnpaulodonnell Linux - Newbie 9 07-28-2015 03:49 PM
Bash Script Loop Question SoulShaker Linux - Server 5 06-17-2009 01:44 PM
Bash script Question while loop glennph93 Programming 6 05-25-2007 03:27 PM
bash script loop bong.mau Programming 6 09-14-2005 07:38 PM
bash script for loop drisay Programming 5 12-25-2004 12:32 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:38 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