Last change
on this file since 1611 was 567, checked in by bcornec, 18 years ago |
Same for mondo: setup modes correctly in SVN and get rid of %attr an %defattr in spec files to get correct packages
|
-
Property svn:keywords
set to
Id
-
Property svn:unix-mode
set to
755
|
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 |
|
---|
6 | IsItValid() {
|
---|
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 |
|
---|
25 | if [ "$#" -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
|
---|
30 | fi
|
---|
31 |
|
---|
32 | LogIt "ask-me-a-question '$1'"
|
---|
33 |
|
---|
34 | res=0
|
---|
35 | while [ "$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
|
---|
44 | done
|
---|
45 |
|
---|
46 | LogIt "result of question = $res"
|
---|
47 | exit $res
|
---|
Note:
See
TracBrowser
for help on using the repository browser.