Little Girl's Mostly Linux Blog

InteractiveHelp

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.

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Comment:

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

Create a free website or blog at WordPress.com.

%d bloggers like this: