Home > linux > Bash script: a simple select menu

Bash script: a simple select menu

As I started using Linux a couple years ago, I noticed I was moving to the command-line for many common tasks. When I noticed I was typing the same commands many times a day, I decided to to write some bash scripts to speed up some of these tasks.

The first part of these scripts is a simple select menu:

It shows several options, you select an option by typing a letter between brackets.
Some options start an other bash script, other options start python scripts.

More code will be released later.
– kdialog version, backup scripts, …

#!/bin/bash
#
# Script to perform some common system operations
#
while :
do
clear
echo "************************"
echo "* My tools *"
echo "************************"
echo "* [b] Backup *"
echo "* [a] Attach sshfs *"
echo "* [u] Unmount sshfs *"
echo "* [l] Server Login ssh *"
echo "* [t] Tunnels over ssh *"
echo "* [x] X-forwarding ssh *"
echo "* [y] YouTube download *"
echo "* [g] Portfolio grabber*"
echo "* [0] Exit/Stop *"
echo "************************"
echo -n "Enter your menu choice [a-0]: "
read yourch
case $yourch in
b) $HOME/.scripts/tools/backup ;;
a) $HOME/.scripts/tools/mount ;;
u) $HOME/.scripts/tools/umount ;;
l) $HOME/.scripts/tools/ssh ;;
t) $HOME/.scripts/tools/tunnel ;;
x) $HOME/.scripts/tools/xforward ;;
k) kate $HOME/.scripts/scripts ;;
g) $HOME/.scripts/tools/pf-grabber.sh ;;
y) python $HOME/.scripts/tools/youtube.py ;;
0) exit 0;;
*) echo "Oopps!!! Please select choice 1,2,3 or 4";
echo "Press Enter to continue. . ." ; read ;;
esac
done

Advertisements
  1. G3n1k
    6 September 2011 at 5:42 pm

    thanks, this tutorial useful for me

  2. Wild Bill
    23 March 2012 at 6:38 pm

    This was useful; in addition to the script itself, the reminder that more is not always better. The logic is the thing that is often overlooked, but not here!! Thanks.

  3. 16 August 2012 at 1:51 am

    thanks for the guide, can I reffer your guide in my script?

    • jeroendoggen
      16 August 2012 at 7:14 am

      Feel free to use this code in any way that fits your purposes.

  4. 18 September 2012 at 10:20 am

    Thank you very much. Jeroen! Very helpful!

  5. mercia
    10 December 2012 at 3:30 am

    Thank you very much :). I’m wondering how to use this code, I don’t understand what is the meaning of syntax from lines 23 until 30 .. is that the directory of a script which has been existed from the system on every linux kernel or is it a script that you wrote it by your own? I need your help for my system programming assignment.. thanks!

    • jeroendoggen
      10 December 2012 at 1:01 pm

      Lines 23-30 are other scripts that I call to do some stuff.
      a) mount sshfs shares
      b) start a backup script
      k) start the kate editor to edit the script itself

      • mercia
        10 December 2012 at 10:05 pm

        thanks jeroendoggen! By the way, what if I want to call an application, for example I want that whenever I press (a) then it would take me to chromium browser? How am I supposed to write the line 23?

      • jeroendoggen
        10 December 2012 at 11:33 pm

        @mercia: have a look at line 29, where I start an application (kate text editor)

  6. 16 April 2013 at 9:48 pm

    thank you very much

  1. 30 June 2010 at 11:26 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: