Little Girl's Mostly Linux Blog

InteractiveHelp

Interactive help

This page was last updated on April 4, 2012.


This script offers two different ways of getting help at the press of a key. Each time you are offered a choice and the script will not move from that offer until one of the suggested keys is pressed:

#!/bin/bash

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;
	};

DONOTHING () {
	echo;
	:
	};

HELPINTERFACE () {
	echo;
	read -s -n1 -p "Press 1 for help1 or 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.

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

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 )

Connecting to %s

Theme: WordPress Classic. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.