source: trunk/mondo/mondo/restore-scripts/mondo/ask-me-a-question @ 1

Last change on this file since 1 was 1, checked in by bcornec, 14 years ago

Initial import from latest mondo-2.04_cvs_20050503/mindi-1.04_cvs_20050503 on http://www.mondorescue.org

File size: 1.0 KB
Line 
1#!/bin/sh
2
3# ask-me-a-question <string> <choices> (<default>)
4# ..returns N integer, Nth position in choices
5
6IsItValid() {
7    local incoming validvalues res i callstr
8    validvalues=$1
9    incoming=$2
10
11    res=`echo "$validvalues" | gawk '{for(i=1;i<=length($0);i++) {print substr($0,i,1);};}' | grep -n "" | grep -i "$incoming" | cut -d':' -f1`
12    if [ "$incoming" = "" ] ; then
13    return -1
14    elif [ "$res" = "" ] ; then
15    return 0
16    else   
17    return $res
18    fi
19
20}
21
22
23# ----------- main -----------
24
25if [ "$#" -ne "2" ] && [ "$#" -ne "3" ] ; then
26    echo "ask-me-a-question <string> <responses> (<default>)"
27    echo "e.g. ask-me-a-question \"Compression level (0-9)?\" \"0123456789\""
28    echo "... only works for integers, or 'y' or 'n'"
29    exit 1
30fi
31
32LogIt "ask-me-a-question '$1'"
33
34res=0
35while [ "$res" -eq "0" ] ; do
36    echo -e -n "$1"
37    read line
38    IsItValid "$2" $line
39    res=$?
40    if [ "$res" = "-1" ] && [ "$#" -eq "3" ] ; then
41    IsItValid "$2" "$3"
42    res=$?
43    fi
44done
45
46LogIt "result of question = $res"
47exit $res
Note: See TracBrowser for help on using the repository browser.