HOWTO’s

BASH Menu System

What is this?
Being a linux geek I know what is on my system. I know everything about it and where to find it. But when you work with others on projects sometimes they aren’t there yet. What this is useful for is if you have ssh access given out to users. Set this up to run when they login and that way there is no need to write a howto for simple Linux programs. This example comes from a public shell server for friends.

The one layer menu code
Open your favorite text editor (vi I hope!) and decide where you are going to put this program. Usual places are /usr/bin or /usr/local/bin. Depends on your preferences. Go ahead and cut-n-paste my example into your window and we will go through the options.
Code:

#!/bin/bash
let "loop=0"
while test $loop == 0
do
clear
echo "Please choose the letter of the game you want to run and enter"
echo "------------------------------------------------------"
echo "a. Check your email"
echo "b. Read news"
echo "c. Text-mode internet browser"
echo "d. IRC Chat"
echo "------------------------------------------------------"
echo "q. quit"
echo "choice?"
read choice

case $choice in q)
let “loop=1”
esac
case $choice in a)
echo “You are starting up pine for your email!”
/usr/bin/pine
esac
case $choice in b)
echo “You are starting up tin for your news reading!”
/usr/bin/tin
esac
case $choice in c)
echo “You are starting up links for your browsing!”
/usr/bin/links
esac
case $choice in d)
echo “You are starting up IRC on dalnet!”
/usr/bin/irssi irc.dal.net
esac
done

As you can see its very simple to read and edit. Obviously you can add more choices and change the ones that are there. All you would do is save this is /usr/bin. Then chmod a+x menu or whatever you happen to call it. Poof pretty simple eh?

Multi-Layer Menu
So what happens if you have so many programs that one menu is simply to large. Go multi-layer! Basically all you will do is instead of making the letter corespond to a program it will corespond to another menu. So you will make another bash script for every menu. It can get very complicated. Obviously this is pushing bash scripting to its limits but it is simple. For more power go Python!

Code:

#!/bin/bash
let "loop=0"
while test $loop == 0
do
clear
echo "Please choose the letter of the menu you want to go to"
echo "--------------------------------------------------------------"
echo "a. Games"
echo "b. Emulators"
echo "c. Multimedia"
echo "d. Internet"
echo "e. Editors"
echo "f. Misc"
echo "--------------------------------------------------------------"
echo "q. quit"
echo "choice?"
read choice

case $choice in q)
let “loop=1”
esac
case $choice in a)
echo “entering games menu”
cd /usr/games/bin
./gamemenu
esac
case $choice in b)
echo “entering emulators menu”
cd /usr/games/bin
./emumenu
esac
case $choice in c)
echo “entering multimedia menu”
cd /usr/games/bin
./mediamenu
esac
case $choice in d)
echo “entering internet menu”
cd /usr/games/bin
./netmenu
esac
case $choice in e)
echo “entering editors menu”
cd /usr/games/bin
./editmenu
esac
case $choice in f)
echo “entering miscelaneous menu”
cd /usr/games/bin
./miscmenu
esac

done

Done!
There are many ways to do this. Some might point out dialog or another program. I guess I am comfy with what I know. Hope it comes to use for others!