Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@bluegraybox bluegraybox commented Aug 31, 2011

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
You can’t perform that action at this time.