Clarify that the argument to -t is in seconds.
[dragonfly/netmp.git] / contrib / top / getans
blob1b741f7cb7c268c99abeee389d044aaec73d6b2c
1 #!/bin/sh
2 # getans prompt type default results_filename
3 # type is one of
4 # number
5 # integer
6 # neginteger
7 # file default=default filename
8 # path
9 # yesno default=0,1 corres yes or no
10 # string (default)
12 RAWPMPT=$1
13 TYP=$2
14 DFLT=$3
15 OFNM=$4
17 ny0="no"; ny1="yes"
18 if [ ${TYP} = "yesno" ]; then
19 eval ny=\$ny${DFLT}
20 pmpt="${RAWPMPT} [$ny]: "
21 else
22 if [ -z "${DFLT}" ]; then
23 pmpt="${RAWPMPT}"
24 else
25 pmpt="${RAWPMPT} [${DFLT}]: "
28 if [ x"`echo -n`" = x-n ]
29 then
30 c=\\c
31 else
32 n=-n
35 while :
37 echo $n "$pmpt"$c
38 read input
39 case "$TYP" in
40 number)
41 tmp=`echo $input | tr -d 0123456789.`
42 if [ -n "$tmp" ]; then
43 echo "Invalid number. Please try again."
44 continue
48 integer)
49 tmp=`echo $input | tr -d 0123456789`
50 if [ -n "$tmp" ]; then
51 echo "Invalid integer. Please try again."
52 continue
56 neginteger)
57 if [ "x$input" != "x-1" ]; then
58 tmp=`echo $input | tr -d 0123456789`
59 if [ -n "$tmp" ]; then
60 echo "Invalid integer. Please try again."
61 continue
66 file)
67 if [ -z "$input" ]; then
68 input=${DFLT}
70 if [ ! -f "$input" -a ! -d "$input" ]; then
71 echo "The file $input does not exist. Please try again."
72 continue
76 path)
77 if [ -z "$input" ]; then
78 input="${DFLT}"
80 if [ ! -f "$input" ]; then
81 path=`echo $PATH | sed -e s'/::/ . /g' -e 's/:/ /g'`
83 for elt in $path; do
84 if [ -f "$elt/$input" ]; then x=1; break; fi
85 done
86 if [ -z "$x" ] ;then
87 echo "The command $input was not found. Please try again."
88 continue
93 yesno)
94 if [ -z "$input" ]; then
95 input="${DFLT}"
96 else
97 case $input in
98 y | yes)
99 input=1 ;;
100 n | no)
101 input=0 ;;
103 echo 'Please answer "yes" or "no".'
104 continue ;;
105 esac
109 *) ;;
110 esac
111 break
112 done
114 if [ -z "$input" ]; then
115 input="${DFLT}"
118 echo $input > ${OFNM}