Simple bash script menu | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Simple bash script menu

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 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 04:43 AM.. Reason: code tags
Sponsored Links
    #2  
Old 01-13-2013
mutley2202 mutley2202 is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 1 September 2014, 11:07 AM EDT
Posts: 28
Thanks: 2
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 04:47 AM.. Reason: code tags
Sponsored Links
    #3  
Old 01-13-2013
Scrutinizer's Avatar
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 25 October 2014, 12:38 PM EDT
Location: Amsterdam
Posts: 9,549
Thanks: 285
Thanked 2,426 Times in 2,174 Posts
Try using a case statement or an if statement.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 04:05 AM
Simple bash script help dentex Shell Programming and Scripting 2 12-27-2010 05:01 AM
Help regarding a bash menu script Vitrophyre Shell Programming and Scripting 5 04-06-2010 12:55 AM
Execute interactive bash menu script in browser with PHP nck Shell Programming and Scripting 1 12-14-2009 07:21 PM
Bash menu script AngelFlesh Shell Programming and Scripting 3 11-29-2009 05:31 PM



All times are GMT -4. The time now is 01:28 PM.