LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Bash Script Problem - Stops after While loop (http://www.linuxquestions.org/questions/linux-newbie-8/bash-script-problem-stops-after-while-loop-807642/)

K_REY_C 05-13-2010 02:44 PM

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.

pixellany 05-13-2010 02:54 PM

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)

yooy 05-13-2010 03:01 PM

while loop need arguments

you can exit while loop with "exit"

catkin 05-13-2010 03:04 PM

Quote:

Originally Posted by yooy (Post 3967348)
you can exit while loop with "exit"

exit will exit the script; to exit a loop use break.

K_REY_C 05-13-2010 03:14 PM

Quote:

Originally Posted by pixellany (Post 3967338)
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

yooy 05-13-2010 03:32 PM

your second while loop lacks "do"

K_REY_C 05-13-2010 03:42 PM

Thanks yooy!

Of course it was an easy answer!

Thanks all for help and quick responses!

KYLE

grail 05-13-2010 07:59 PM

Please mark as SOLVED once you have your answer ;)


All times are GMT -5. The time now is 01:59 AM.