printERROR “Insufficient Arguments.” return 1 fi DEF_ARG=”" YESNO=”"

printERROR “Insufficient Arguments.” return 1 fi DEF_ARG=”" YESNO=”" case “$2″ in [yY]|[yY][eE][sS]) DEF_ARG=y ;; [nN]|[nN][oO]) DEF_ARG=n ;; esac while : do printf “$1 (y/n)? ” if [ -n “$DEF_ARG” ] ; then printf “[$DEF_ARG] ” fi read YESNO if [ -z “$YESNO” ] ; then YESNO=”$DEF_ARG” fi case “$YESNO” in [yY]|[yY][eE][sS]) YESNO=y ; break ;; [nN]|[nN][oO]) YESNO=n ; break ;; *) YESNO=”" ;; esac done export YESNO unset DEF_ARG return 0 } Before you look at an example of this function in use, examine how it works. As indicated by the comments, this function can handle up to two arguments. It treats the first argument as the prompt and the second argument as the default answer to the prompt. First, this function checks that at least one argument is given. If no arguments are given, you return from the function with the error message ERROR: Insufficient Arguments. Next, set the variables DEF_ARG and YESNO to null, in order to avoid using the values stored in them from a
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.

Leave a Reply