# SccsId[] = "%W% (USL function) %G%"
PYN_name="PAUSE_Y_OR_N"
if [ ".${SECONDS}" = "." ]; then # Bourne function already loaded?
[ ."`set|egrep '^$PYN_name\(\)\{$'`" != . ] && PYN_loaded=1
else # Korn or Bash shell and function already loaded?
if [ `expr "\`uname -s\`" : "[Ll][Ii][Nn][Uu][Xx]"` -eq 0 ]; then
[ ."`typeset +f|awk '/^'$PYN_name'[=\(]?/'`" != . ] && PYN_loaded=1
else # Linux
[ ."`typeset -F|awk '/^'$PYN_name'[=\(]?/'`" != . ] && PYN_loaded=1
fi
fi
if [ 0${PYN_loaded} -eq 0 ]; then
#----------------------------------------------------------------------#
PAUSE_Y_OR_N() # Function documentation located at bottom. #
#----------------------------------------------------------------------#
{ [ ."${AWK}" = . ] && { { [ -x /usr/bin/nawk ] && AWK=/usr/bin/nawk; } \
|| { [ -x /bin/gawk ] && AWK=/bin/gawk ; } \
|| { [ -x /usr/bin/awk ] && AWK=/usr/bin/awk ; }; }
#------------------------------------------------------------#
# If the following variables are not set, use these defaults.#
#------------------------------------------------------------#
: ${script_name:=`basename $0`}
: ${name_root:=`echo $script_name|$AWK '{sub(/^\.+/,"");sub(/\..*/,"");print}'`}
if [ ."$log" = . ]; then
log=$name_root.log
[ ."$teelog" = . ] && teelog="cat"
fi
if [ .${SHLIB} = . ]; then SHLIB=/usr/local/scripts; export SHLIB; fi
. $SHLIB/readkey.sh # Function dependencies
#--------------------------------------------------------------#
# User give us "-1" option? This option means that the user #
# doesn't want to have to press "enter"--he wants to enter one #
# (and only one) key--so we use the library function READKEY #
# (it uses stty and dd). Otherwise we use "read" command. #
#--------------------------------------------------------------#
if [ ."$1" = ."-1" ]; then
PYN_1_char=1; shift
else
PYN_1_char=0
fi
if [ .$TERM != . ]; then # If running interactively, prompt user.
PYN_1_prompt="$*\c"
#---------------------------------------------#
# If we have text string, then use the string.#
# Else, prompt user with default string. #
#---------------------------------------------#
if [ $# -gt 0 ]; then
PYN_prompt="$*"
else
PYN_prompt="Continue? y or n [n]:"
fi
/bin/echo "$PYN_prompt\c"
if [ $PYN_1_char -eq 0 ]; then
read PYN_read # Read response using normal "read".
else
PYN_read="`READKEY`" # Read response (READKEY lib function).
echo "" # Ensures newline to stdout before subsequent output.
fi
PYN_read=`$AWK -v s="$PYN_read" \
'BEGIN {
print s
s = substr(tolower(s),1,1)
if (s == "y") exit 1
else exit 0
}'`
PYN_status=$?
[ "$teelog" != "cat" ] && echo "$PYN_prompt $PYN_read" >> $log
return $PYN_status
else
return 0 # If not running interactively, return 0 for "no."
fi
} # "PYN_" prefix identifies this function's variables.
fi
#======================================================================#
# D O C U M E N T A T I O N #
#======================================================================#
# #
# Author: Bob Orlando #
# #
# Date: December 14, 1996 #
# #
# Program ID: pause_y_or_n.sh #
# #
# Usage: PAUSE_Y_OR_N [-1] "text string" #
# -1 Read one and only one character #
# (ignores CR). #
# #
# Purpose: Prompt the user with "text string" and pause until #
# we receive an answer. #
# #
# Globals: No global variables are assigned in this function. #
# "PYN_" prefix identifies local function variables. #
# #
# Exit_status: Returns true or false. True (1) means the user #
# answered "yes," false (0) means "no" (the default). #
# #
# Calls: READKEY library function. #
# #
# Notes: If running in batch mode (e.g. from cron), then the #
# function simply returns a "no." #
# #
# Modified: 2004-04-02 Bob Orlando #
# v1.10 * Expand $AWK testing and assignment. #
# #
# 2004-03-03 Bob Orlando #
# v1.9 * Change set|egrep|awk to just set|egrep. #
# #
#----------------------------------------------------------------------#
|