Sponsored Content
Top Forums Shell Programming and Scripting Execute function as soon as input is provided in menu drive shell script Post 302975840 by kiran_j on Monday 20th of June 2016 02:31:39 AM
Old 06-20-2016
Execute function as soon as input is provided in menu drive shell script

Hi All,

I have a menu driven scripts. As you know while running the script we have to input the option such as 1,2, and 3 to execute function accordingly. but after selecting the input we have to press Enter.

My requirement is to execute function as soon as we press the option.

Is there any way to do this? Please suggest.

Display Menu:

Code:
Code:
-------------------------------------
            Main Menu
-------------------------------------
[1] Option 1
[2] Option 2
[3] Option 3
[4] Option 4
[5] Exit
=====================================
Enter your menu choice [1-5] [Default :1]:


Current Shell Script Code:


Code:


Code:
#!/usr/bin/bash

# Menu Item

main_menu()
{

while :
do
	clear
	echo " "
	echo "-------------------------------------"
	echo "            Main Menu "
	echo "-------------------------------------"
	echo "[1] Option 1"
	echo "[2] Option 2"
	echo "[3] Option 3"
	echo "[4] Option 4"
	echo "[5] Exit"
	echo "====================================="
	echo "Enter your menu choice [1-5] [Default : 1]: \c "
	read m_menu
	
	case "$m_menu" in

		1) option_1;;
		2) option_2;;
		3) option_3;;
		4) option_4;;
		5) exit 0;;
                "") option_1;;
		*) echo "\nOpps!!! Please Select Correct Choice";
		   echo "Press ENTER To Continue..." ; read ;;
	esac
done
}

option_1()
{
  echo "option 1"
  echo "\nPress ENTER To Continue..."
    read
	return
}

option_2()
{
	echo "option 2"
	echo "\nPress ENTER To Continue..."
    read
	return
}

option_3()
{
	echo "option 3"
	echo "\nPress ENTER To Continue..."
    read
	return
}

option_4()
{
	echo "option 4"
	echo "\nPress ENTER To Continue..."
    read
	return
}

main_menu


Regards,
Kiran

Last edited by kiran_j; 06-20-2016 at 03:37 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execute interactive bash menu script in browser with PHP

I have an interactive menu script written in bash and I would like use PHP to open the interactive bash menu in a browser. Is this possible? Using the sytem() function in php runs the script but it's all garbled. Seems like maybe a terminal window needs to be opened in php first? ... (1 Reply)
Discussion started by: nck
1 Replies

2. Shell Programming and Scripting

How to use ssh execute other shell script on other host (shell script include nohup)?

i want use ssh on the host01 to execute autoexec.sh on the host02 like following : host01> ssh host02 autoexec.sh autoexec.sh include nohup command like follwing : nohup /home/jack/deletedata.sh & after i execute ssh host02 autoexec.sh one the host01. i can't found deletedata.sh... (1 Reply)
Discussion started by: orablue
1 Replies

3. Shell Programming and Scripting

Help to write a script or program to automatic execute and link input file data

Output file template format <input_file_name>a</input_file_name> <total_length_size>b</total_length_size> <log_10_length_size>c</log_10_length_size> Input_file_1 (eg. sample.txt) SDFSDGDGSFGRTREREYWW Parameter: a is equal to the input file name b is equal to the total length of... (2 Replies)
Discussion started by: perl_beginner
2 Replies

4. Shell Programming and Scripting

function from shell input

Hi all i have the command called printer which needs a usernmae for example i would run the commnad printer <username> how can i write i quick script in perl that if the username is ab then write "denined" and if it is anything else it will work thanks Adam (1 Reply)
Discussion started by: ab52
1 Replies

5. Shell Programming and Scripting

Shell Script to execute Oracle query taking input from a file to form query

Hi, I need to query Oracle database for 100 users. I have these 100 users in a file. I need a shell script which would read this User file (one user at a time) & query database. For instance: USER CITY --------- ---------- A CITY_A B CITY_B C ... (2 Replies)
Discussion started by: DevendraG
2 Replies

6. UNIX for Dummies Questions & Answers

[ASK]execute shell with function in solaris

dear all i need your advice in shell with solaris i have testing script like this #!/usr/bin/bash function test(){ echo "testing only" } ## execute function ## test but if i running always got error like this test.sh: syntax error at line 1: `(' unexpected who can i running this... (7 Replies)
Discussion started by: zvtral
7 Replies

7. Shell Programming and Scripting

Want to use function and execute the below query in script.

#!/bin/bash function getDeliveredDispatches(firstDateTime, lastDateTime, limit) { var cursor = db.dispatches.find( {$and: }} ]}, {"deliveryGroupId" : 1, "batchId": 1, "statusHistory.code" : 1} ); var wrongDispatchesIds = ; print("Number of dispatches selected based on filter = " +... (2 Replies)
Discussion started by: neel2462
2 Replies

8. Shell Programming and Scripting

Script to select the rows from the feed file based on the input value provided

Hi Folks, I have the below feed file named abc1.txt in which you can see there is a title and below is the respective values in the rows and it is completely pipe delimited file ,. ... (3 Replies)
Discussion started by: punpun66
3 Replies

9. Shell Programming and Scripting

Need help to write a function in shell scripting to execute sql files

Hi, I am new to shell scripting and i need to write a automation script to execute sql files. I need to check the table if it is there in system tables and need to write a function to call the .sql files. For ex. I have a.sql,b.sql,c.sql files, where the sql file contains DELETE and INSERT... (1 Reply)
Discussion started by: Samah
1 Replies

10. UNIX for Beginners Questions & Answers

How to iterate Grep via all patterns provided in an input file?

When I use the following grep command with options -F and -f, its just displaying the text related to only the last pattern. Command: $ grep -f pattern_file.txt input_file.txt Output: doc-C2-16354 Even the following command yields the same output: Command: $ grep -Ff pattern_file.txt... (6 Replies)
Discussion started by: nsai
6 Replies
echo(3XCURSES)						  X/Open Curses Library Functions					    echo(3XCURSES)

NAME
echo, noecho - enable/disable terminal echo SYNOPSIS
cc [ flag... ] file... -I /usr/xpg4/include -L /usr/xpg4/lib -R /usr/xpg4/lib -lcurses [ library... ] c89 [ flag... ] file... -lcurses [ library... ] #include <curses.h> int echo(void); int noecho(void); DESCRIPTION
The echo() function enables Echo mode for the current screen. The noecho() function disables Echo mode for the current screen. Initially, curses software echo mode is enabled and hardware echo mode of the tty driver is disabled. The echo() and noecho() functions control soft- ware echo only. Hardware echo must remain disabled for the duration of the application, else the behavior is undefined. RETURN VALUES
Upon successful completion, these functions return OK. Otherwise, they return ERR. ERRORS
No errors are defined. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |Unsafe | +-----------------------------+-----------------------------+ SEE ALSO
getch(3XCURSES), getstr(3XCURSES), initscr(3XCURSES), libcurses(3XCURSES), scanw(3XCURSES), attributes(5), standards(5) SunOS 5.11 5 Jun 2002 echo(3XCURSES)
All times are GMT -4. The time now is 01:15 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy