-
Closing Continuous "while" loop
I put this script together and would like to close the script by typing q to exit cleanly. Please do not recommend me doing this by "case." I know how to do this through "case." I'm doing this through "if" and want to keep it that way. My problem is when I press q,
I get this:
q
This month does not exist.
Choose another month or q to quit.
mint ~ #
I would like if it is humanly possible to not see the above, which are parts of the script. I'd like clean exit when typing the q key. I'm submitting the present script below, and I ask that you not treat me as a novice, as I am new to this and trying to learn. Thank you,
joe.
echo "Please choose a month from January to December and that month will display which holiday is related to that month."
while [ "$month" != "q" ]
do
read month
if [ "$month" = "January" ]
then
echo "Martin Luther King Day is in the month of January."
elif
[ "$month" = "February" ]
then
echo "President's Day is in the month of February."
elif
[ "$month" = "March" ]
then
echo "There is no holiday in the month of March."
elif
[ "$month" = "April" ]
then
echo "There is no holiday in the month of April."
elif
[ "$month" = "May" ]
then
echo "Memorial Day is in the month of May."
elif
[ "$month" = "June" ]
then
echo "There is no holiday in the month of June."
elif
[ "$month" = "July" ]
then
echo "The Fourth of July is in the month of July."
elif
[ "$month" = "August" ]
then
echo "There is no holiday in the month of August."
elif
[ "$month" = "September" ]
then
echo "Labor Day is in the month of September."
elif
[ "$month" = "October" ]
then
echo "Columbus Day is in the month of October."
elif
[ "$month" = "November" ]
then
echo "Thanksgiving one of the most wonderful holidays, is in the month of November."
elif
[ "$month" = "December" ]
then
echo "Christmas is in the month of December."
else
echo "This month does not exist."
fi
echo "Choose another month or q to quit."
done
-
Thats because your read is wihin the loop, so it must process the all the if tests, fail, then it gets to the while statement.
try moving the read as the LAST line in the while loop, and add 1 read just prior to entering the loop.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|