Interactive help
This page was last updated on January 19, 2017.
This script offers two different ways to get help at the press of a key. Each time you’re offered a choice and the script will not move from that offer until one of the suggested keys is pressed:
#!/bin/bash
DONOTHING () {
echo;
:
};
HELPINTERFACE () {
HELP1 () {
echo;
echo "This is help1.";
echo;
read -s -n1 -p "Press x to exit help or press 2 for help2. (x/2)" keypress;
if
[ "$keypress" = "x" ];
then
DONOTHING;
elif
[ "$keypress" = "2" ];
then
echo;
HELP2;
else
HELP1;
fi;
};
HELP2 () {
echo;
echo "This is help2.";
echo;
read -s -n1 -p "Press x to exit help or press 1 for help1. (x/1)" keypress;
if
[ "$keypress" = "x" ];
then
DONOTHING;
elif
[ "$keypress" = "1" ];
then
echo;
HELP1;
else
HELP2;
fi;
};
echo;
read -s -n1 -p "Press 1 for help1 or press 2 for help2. (1/2)" keypress;
echo;
if
[ "$keypress" = "1" ];
then
HELP1;
elif
[ "$keypress" = "2" ];
then
HELP2;
else
HELPINTERFACE;
fi;
};
OFFERTOHELP () {
echo;
read -s -n1 -p "Would you like some help? (y/n)" keypress;
echo;
if
[ "$keypress" = "y" ];
then
HELPINTERFACE;
elif
[ "$keypress" = "n" ];
then
DONOTHING;
else
OFFERTOHELP;
fi;
};
OFFERTOHELP;
echo;
echo "This is the script running after the choices are made.";
echo;
Obligatory Happy Ending
And they all lived happily ever after. The end.

Comment: