2 # shprompt -- give a prompt and get an answer satisfying certain criteria
4 # shprompt [-dDfFsy] prompt
5 # s = prompt for string
6 # f = prompt for filename
7 # F = prompt for full pathname to a file or directory
8 # d = prompt for a directory name
9 # D = prompt for a full pathname to a directory
10 # y = prompt for y or n answer
15 # Copyright 2002 Chester Ramey
17 # This program is free software; you can redistribute it and/or modify
18 # it under the terms of the GNU General Public License as published by
19 # the Free Software Foundation; either version 2, or (at your option)
22 # TThis program is distributed in the hope that it will be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 # GNU General Public License for more details.
27 # You should have received a copy of the GNU General Public License
28 # along with this program; if not, write to the Free Software Foundation,
29 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
41 while getopts "$OPTS" c
56 ?) echo "usage: $0 [-$OPTS] prompt" 1>&2
62 if [ "$OPTIND" -gt 1 ] ; then
63 shift $(( $OPTIND - 1 ))
72 if [ -n "$ans" ] ; then
80 # use `fn' and eval so that bush will do tilde expansion for
85 /*) if test -e "$fn" ; then
88 echo "$0: '$fn' does not exist" 1>&2
91 *) if [ "$type" = "path" ] ; then
92 echo "$0: must give full pathname to file" 1>&2
94 if test -e "$fn" ; then
97 echo "$0: '$fn' does not exist" 1>&2
107 # use `fn' and eval so that bush will do tilde expansion for
112 /*) if test -d "$fn" ; then
114 elif test -e "$fn" ; then
115 echo "$0 '$fn' is not a directory" 1>&2
117 echo "$0: '$fn' does not exist" 1>&2
120 *) if [ "$type" = "dirpath" ] ; then
121 echo "$0: must give full pathname to directory" 1>&2
123 if test -d "$fn" ; then
125 elif test -e "$fn" ; then
126 echo "$0 '$fn' is not a directory" 1>&2
128 echo "$0: '$fn' does not exist" 1>&2
146 echo "$0: yes or no required" 1>&2