Skip to content

Instantly share code, notes, and snippets.

@bluegraybox
Created August 31, 2011 21:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bluegraybox/1184819 to your computer and use it in GitHub Desktop.
Save bluegraybox/1184819 to your computer and use it in GitHub Desktop.
Framework for shell script wizard.
#!/bin/bash
# Interactive wizard to walk the user through a process.
# Tracks steps completed; allows user to exit at any point and pick back up there.
function step1 () {
read -p "step 1 ok, $1? " ok
}
function step2 () {
read -p "step 2 ok, $1? " ok
}
function step3 () {
read -p "step 3 ok, $1? " ok
}
function step4 () {
read -p "step 4 ok, $1? " ok
}
function step5 () {
read -p "step 5 ok, $1? " ok
}
function step6 () {
read -p "step 6 ok, $1? " ok
}
function step7 () {
read -p "step 7 ok, $1? " ok
}
base=${0%.sh}
if [ ! -e $base.cfg ] ; then
# initialize the file with all the steps
echo -e "step1\nstep2\nstep3\nstep4\nstep5\nstep6\nstep7" > $base.cfg
fi
for x in `grep -v ^# $base.cfg` ; do
$x foo
# mark the step complete with a hash.
sed -i "s/$x/# $x/;" $base.cfg
done
@bluegraybox
Copy link
Author

Example session:
$ ./wizard.sh
step 1 ok, foo?
step 2 ok, foo?
step 3 ok, foo?
[ctrl-c]
$ ./wizard.sh
step 3 ok, foo?
step 4 ok, foo?
step 5 ok, foo?
step 6 ok, foo?
[ctrl-c]
$ ./wizard.sh
step 6 ok, foo?
step 7 ok, foo?
[ctrl-c]
$ ./wizard.sh
$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment