Sponsored Content
Full Discussion: Global exit listener in bash
Top Forums Shell Programming and Scripting Global exit listener in bash Post 302852981 by Chubler_XL on Thursday 12th of September 2013 10:46:29 PM
Old 09-12-2013
How about using stty to remap CTRL-Q to interrupt and then trapping the signal? Of course this would also stop anyone breaking out of the script with CTRL-C which may or may not be a good thing.

---------- Post updated at 12:46 PM ---------- Previous update was at 12:38 PM ----------

Another option is to write your own menu function and add quit option by default (something like this):

Code:
mymenu()
{   select opt in $@ Quit
     do
          if [ -z "$opt" ]
          then
              echo "Option $REPLY is invalid"
           else
               [ "$opt" = "Quit" ] && exit 1
               return $REPLY
           fi
     done
}

mymenu one two three
case $opt in
   one) echo "You picked one" ;;
   two) echo "Two" ;;
esac


Last edited by Chubler_XL; 09-12-2013 at 11:54 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to get exit status codes in bash from Perl?

I apologize if I have already posted this query. I scanned back quite a few pages but could not find such a query. If my perl code contains "exit(33)" how can I get that value in bash for use in a "if" statement. Thanks, Siegfried (5 Replies)
Discussion started by: siegfried
5 Replies

2. UNIX for Advanced & Expert Users

Setting global variables with BASH/Linux

I am using functions in a script and for some strange reason the EXPORT command doesnt seem to be making my variables global. Anyone got any ideas? I am using one function to pass some output top another using the pipe command, eg Function 1 | Function 2 Function 2 reads the value... (3 Replies)
Discussion started by: gregf
3 Replies

3. Shell Programming and Scripting

Functions, exit, and kill in bash

Hello Okay, for reasons related to sourcing a script from another script, I've had to put my main loop into a function, and from there I call other functions. My problem then is exiting from deep within the function call stack. I used to simply call exit, and that would accomplish what I... (1 Reply)
Discussion started by: brsett
1 Replies

4. Shell Programming and Scripting

Bash script wont exit?

Solved Stupidly I didn't put brackets around the , thanks for all the help guys if ps ax | grep Cluster__check.bash | grep -v grep > /dev/null -- fails (if ps ax | grep Cluster__check.bash | grep -v grep > /dev/null) --works (3 Replies)
Discussion started by: danmc
3 Replies

5. Shell Programming and Scripting

Bash won't exit as expected

Hi there, following code snippet should output nothing, IMHO. But the result is "THE END". #!/bin/bash if true ; thenexit fi | grep "somesearchstring" echo "THE END"using bash 4.1.9(1) Bug or feature? Hagen (5 Replies)
Discussion started by: montour
5 Replies

6. Shell Programming and Scripting

Global replace with perl in bash

I am newbie to perl, I am trying to use the below syntax to replace globally a string with a variable. $ bash -version GNU bash, version 2.05b.0(1)-release (powerpc-ibm-aix5.1) Copyright (C) 2002 Free Software Foundation, Inc. $ perl -version This is perl, v5.8.8 built for... (2 Replies)
Discussion started by: jville
2 Replies

7. Ubuntu

Exit user in bash script

I'm writing a bunch of scripts to automatically configure Ubuntu and I want to run the code below to remove the white dots from the login screen: sudo xhost +SI:localuser:lightdm sudo su lightdm -s /bin/bash gsettings set com.canonical.unity-greeter draw-grid false The problem is that... (3 Replies)
Discussion started by: maerlyngb
3 Replies

8. Programming

Global variable in for loop (BASH)

Hello, I'm trying to read the variable "pause" from a for loop without luck. The function is dependant on the outcome of the test within the loop. If i run this, pause is always 0 within the function. Any ideas? Thanks. pause=0 users=1 (for (( ; ; )) do speed=`cat speed.log` ... (7 Replies)
Discussion started by: shadyuk
7 Replies

9. Shell Programming and Scripting

Bash to exit on no reponse

The below bash does not seem to exit if the user response is n N no No. Is the synatax incorrect? Thank you :). Bash read -r -p "Is this correct? " response if ] then echo "The files do not match" && exit ;; else .... do something fi (5 Replies)
Discussion started by: cmccabe
5 Replies

10. Shell Programming and Scripting

Ignore exit status for #!/bin/bash -e

I have a file /u/setuplink.txt more setuplink.txt ln -s /u/force.sh stopf.sh ln -s /u/tnohup.sh tnohup.sh ln -s /u/quick.sh startquick.sh more runstat.sh #!/bin/bash -e echo "START" /u/setuplink.txt echo "END" i wish to exit the runstat.sh for any errors except if the link... (2 Replies)
Discussion started by: mohtashims
2 Replies
PLMESHC(3plplot)						    PLplot API							  PLMESHC(3plplot)

NAME
plmeshc - Magnitude colored plot surface mesh with contour. SYNOPSIS
plmeshc(x, y, z, nx, ny, opt, clevel, nlevel) DESCRIPTION
Identical to plmesh but with extra functionalities: the surface mesh can be colored accordingly to the current z value being plotted, a contour plot can be drawn at the base XY plane, and a curtain can be drawn between the plotted function border and the base XY plane. Redacted form: plmeshc(x, y, z, opt, clevel) This function is used in example 11. ARGUMENTS
x (PLFLT *, input) Pointer to set of x coordinate values at which the function is evaluated. y (PLFLT *, input) Pointer to set of y coordinate values at which the function is evaluated. z (PLFLT **, input) Pointer to a vectored two-dimensional array with set of function values. nx (PLINT, input) Number of x values at which function is evaluated. ny (PLINT, input) Number of y values at which function is evaluated. opt (PLINT, input) Determines the way in which the surface is represented. To specify more than one option just add the options, e.g. DRAW_LINEXY + MAG_COLOR opt=DRAW_LINEX: Lines are drawn showing z as a function of x for each value of y[j]. opt=DRAW_LINEY: Lines are drawn showing z as a function of y for each value of x[i]. opt=DRAW_LINEXY: Network of lines is drawn connecting points at which function is defined. opt=MAG_COLOR: Each line in the mesh is colored according to the z value being plotted. The color is used from the cur- rent colormap 1. opt=BASE_CONT: A contour plot is drawn at the base XY plane using parameters nlevel and clevel. opt=DRAW_SIDES: draws a curtain between the base XY plane and the borders of the plotted function. clevel (PLFLT *, input) Pointer to the array that defines the contour level spacing. nlevel (PLINT, input) Number of elements in the clevel array. AUTHORS
Geoffrey Furnish and Maurice LeBrun wrote and maintain PLplot. This man page was automatically generated from the DocBook source of the PLplot documentation, maintained by Alan W. Irwin and Rafael Laboissiere. SEE ALSO
PLplot documentation at http://plplot.sourceforge.net/resources. August, 2012 PLMESHC(3plplot)
All times are GMT -4. The time now is 04:35 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy