Unix/Linux Go Back    


UNIX for Dummies Questions & Answers This forum is closed for new posts. Please post beginner questions to learn unix and learn linux in this forum UNIX for Beginners Questions & Answers

Simple bash script menu

UNIX for Dummies Questions & Answers


 
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-13-2013
fusetrips fusetrips is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 27 January 2013, 8:39 AM EST
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Simple bash script menu

Dear Sir,

May I know how do I go about adding the following feature into the script below:

When user enter values other than 1,2,3,4,

a) Message “Wrong entry !!! Pls select 1,2,3 or 4” is displayed
b) The screen is cleared again and the menu is displayed.



Code:
#!/bin/bash
clear
var=1
until [ $var -eq 4 ] 
do
echo "Menu"
echo "(1) Item 1"
echo "(2) Item 2"
echo "(3) Item 3"
echo "(4) Exit"
read -p "Enter your choice " var
clear
echo "Your choice is $var"
done

I've tried adding * but it returns an syntax error.

Thank you.

Last edited by Scrutinizer; 01-13-2013 at 05:43 AM.. Reason: code tags
Sponsored Links
    #2  
Old Unix and Linux 01-13-2013
mutley2202 mutley2202 is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 9 October 2016, 10:07 AM EDT
Posts: 60
Thanks: 12
Thanked 0 Times in 0 Posts
Hope this helps

Hi Fusetrips,
Try using the below its off one of the scripts I already have built.


Code:
*) echo "Please select a valid choice ";
echo "Press a key to return to the menu. . ." ; read ;;
esac
:
done


to the user running the script it looks like the below


Code:
Enter your menu choice:
30
Please select a valid choice
Press a key to return to the menu. . .

once a key has been pressed it returns to the menu

Last edited by Scrutinizer; 01-13-2013 at 05:47 AM.. Reason: code tags
Sponsored Links
    #3  
Old Unix and Linux 01-13-2013
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 4 December 2016, 6:12 AM EST
Location: Amsterdam
Posts: 11,099
Thanks: 440
Thanked 3,108 Times in 2,749 Posts
Try using a case statement or an if statement.
Sponsored Links
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help making simple perl or bash script to create a simple matrix torchij Shell Programming and Scripting 16 04-26-2012 05:05 AM
Simple bash script help dentex Shell Programming and Scripting 2 12-27-2010 06:01 AM
Help regarding a bash menu script Vitrophyre Shell Programming and Scripting 5 04-06-2010 01:55 AM
Execute interactive bash menu script in browser with PHP nck Shell Programming and Scripting 1 12-14-2009 08:21 PM
Bash menu script AngelFlesh Shell Programming and Scripting 3 11-29-2009 06:31 PM



All times are GMT -4. The time now is 10:11 AM.