Repetitive ending of script

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Repetitive ending of script
# 1  
Old 08-28-2013
Repetitive ending of script


I am quit satisfied with this scrtipt and really don't want to change anything but the end. I get a repetitve option when I want to "quit"
and don't know why. What am I missing? When I press q to quit
with this script, I get an EXTRA "Enter " How do I correct this so that when I
press q, I immediately exit, and see nothing else but the prompt and no additional words. Thanks.


The script is below.

echo "Enter 1 to Add"
echo "Enter 2 to Subtract"
echo "Enter 3 to Multiply"
echo "Enter 4 to Divide"
echo "or q to quit"
while [ "$Enter" != "q" ]
read Enter
case $Enter in
1) echo "Add"
echo "Enter a number"
read num1
echo "Enter another number"
read num2
sum=$((num1 + num2))
echo "The sum of number 1 and number 2 is: $sum";;
2) echo "Subtract"
echo "Enter a number"
read num1
echo "Enter another number"
read num2
sub=$((num1 - num2))
echo "The difference of number 1 and number 2 is: $sub";;
3) echo "Multiply"
echo "Enter a number"
read num1
echo "Enter another number"
read num2
prod=$((num1 * num2))
echo "The product of number 1 and number 2 is: $prod";;
4) echo "Divide"
echo "Enter a number"
read num1
echo "Enter another number"
read num2
div=$((num1 / num2))
echo "The quotient of number 1 and number 2 is: $div";;
echo "Enter another selection or q to quit"

Last edited by Franklin52; 08-28-2013 at 05:44 AM.. Reason: Please use code tags
# 2  
Old 08-28-2013
You may add
q) exit;;

before the esac statement towards the end.

Last edited by vbe; 08-28-2013 at 12:07 PM.. Reason: missing / for icode.tag hehe
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to check line end not ending with comma

I have several line in a text file. for example I like apple; I like apple I like orange; Output: I like apple I try to useif grep -q "!\;$"; then (Not work) Please use CODE tags when displaying sample input, sample output, and code segments (as required by forum rules). (1 Reply)
Discussion started by: cmdcmd
1 Replies

2. UNIX for Beginners Questions & Answers

School ending Script

Hello beautiful people, I would like to kindly ask you to help me with my school leaving project. Unfortunatelly due to family problems I felt into trouble and I am on able to finish my project due to schedule. I would like to ask you to review this script and give me any hints that you could.... (2 Replies)
Discussion started by: Cerda
2 Replies

3. Shell Programming and Scripting

I need help to removing repetitive lines

Hello SuperUsers! First i wanna say my english sucks.. Don't hate me for that. :rolleyes: I need to make a Bash for removing smilar lines from an output file. My output file always same. Line 1 & 2 Stays. And others similar to this lines needs to be delete. </UsageData><?xml version="1.0"... (4 Replies)
Discussion started by: morphin
4 Replies

4. Shell Programming and Scripting

UNIX script abruptly ending due to ssh command

Below UNIX script abruptly ends while reading second line from file. When I comment 'ssh' command the script works as expected. I think I will have to run ssh command in a different process, but haven't got a handle yet as regards to how to do that. Any help in resolving this problem is highly... (1 Reply)
Discussion started by: jeeteshkc
1 Replies

5. Shell Programming and Scripting

sed in script creates output file ending with '?' (^M)

Hi, I'm trying to use sed within a shell script (bash, running ubuntu). The command works fine from the command line, but when I use it within the script, rather than creating a file with the name I've specified, it creates one that ends with a question mark '?' when you use ls, e.g.... (3 Replies)
Discussion started by: jennykay
3 Replies

6. Shell Programming and Scripting

Ending script at specific time.

Hello Everybody.. I've written the script that kick off through CRON job and kill itself by specific time. I've start time and end time specify in env file. i.e START_TIME=1500 (03:00 PM) END_TIME=0600 (06:00 AM) It always works good if my START_TIME is before midnight and my... (4 Replies)
Discussion started by: nirav_soni
4 Replies

7. Shell Programming and Scripting

Ending a script

Hi all, I am trying to end a Menu script. Can people suggest various methods please? At the moment I am doing: quit=n while do ...Code Code Code... read userinput case $userinput in q|Q) quit=y;; esac done But this doesn't seem to work every time, occasionally it will work,... (6 Replies)
Discussion started by: mikejreading
6 Replies

8. Shell Programming and Scripting

Ending script after a specified time.

Hi All, I am having a script, which run fine. But what I want to do is that the script should run for specified time and terminate then ( say for a minute). Can somebody help me for this. I would be greatful. Thanks, Aru (8 Replies)
Discussion started by: aarora_98
8 Replies

9. UNIX for Dummies Questions & Answers

Repetitive Tasks

Could someone tell me how I can simplify the script that follows!!! I know that there must be a way how to grep Average from sar01.................. sar02 ....................... sar03....................... sar04... (3 Replies)
Discussion started by: JairGuerra
3 Replies

10. Shell Programming and Scripting

ssh not ending (sometimes) from inside a script, why?

Okay I have this script file that runs from cron and most the time it works just find. Except every so often one of the three ssh commands I have in it just doesn't know it's done and that of course causes the whole thing to hang! The ssh command has executed. I can tell this because the command... (1 Reply)
Discussion started by: stilllooking
1 Replies
Login or Register to Ask a Question