# SccsId[] = "%W% (USL function) %G%"
PV_name="PRINT_VARS"
if [ ".${SECONDS}" = "." ]; then # Bourne function already loaded?
[ ."`set|egrep '^$PV_name\(\)\{$'`" != . ] && PV_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 '/^'$PV_name'[=\(]?/'`" != . ] && PV_loaded=1
else # Linux
[ ."`typeset -F|awk '/^'$PV_name'[=\(]?/'`" != . ] && PV_loaded=1
fi
fi
if [ 0${PV_loaded} -eq 0 ]; then
#----------------------------------------------------------------------#
PRINT_VARS() # 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.#
#------------------------------------------------------------#
: ${id_num=`id|sed 's/^\(uid=\)\([0-9]*\)\(.*\)/\2/'`}
: ${id_hex=`echo "obase=16;$id_num"|bc`}
: ${script_name:=`basename $0`}
: ${name_root:=`echo $script_name|$AWK '{sub(/^\.+/,"");sub(/\..*/,"");print}'`}
: ${yymmddhhmiss:=`date '+%y''%m%d%H''%M''%S'`}
: ${Xtimestamp:=`echo "obase=16;$yymmddhhmiss+$$"|bc`}
: ${verbose:=0}
: ${sp:=" "}
: ${tmp:=/var/tmp}
PV_ID="$script_name($PV_name)"
[ ."$log" = . ] && log=$name_root.log
[ ."$teelog" = . ] && teelog="cat"
#----------------------------#
# Parse any function options.#
#----------------------------#
PV_justify="r" # Right justify is the default.
PV_sort="cat" # Defaults to unsorted output.
PV_root=$tmp/$name_root"_PV_go_"$id_hex
PV_err=$PV_root"."$Xtimestamp
while getopts ls PV_opt 2>> $PV_err
do
case $PV_opt in
l ) PV_justify="l";;
s ) PV_sort="sort -bd +0 -1";;
\? ) echo "$PV_ID" \
"Invalid option: -`sed 's/^.*-- //' $PV_err`" 1>&2
;;
* ) ;;
esac
done
shift `expr $OPTIND - 1` # Shift past options to remaining args
#------------------------------------------------------------------#
# Must reset this dog if this function is apt to be called again #
OPTIND=1 # (try and find this fact documented anywhere else). #
#------------------------------------------------------------------#
[ ."$PV_root" != . ] && \rm -f $PV_root* > /dev/null 2>&1
if [ $# -gt 0 ]; then
#---------------------------------------------------------------#
# Trick here is to run this entire block of code in background #
# (hence the beginning and end parentheses on separate lines). #
# Doing this allows us to use environmental variables (the only #
# ones nawk is capable of seeing) without affecting any in #
# foreground which might have the same names. #
# #
(# Begin export and nawk process in background.
export $*
echo "$*" | $AWK -v j=$PV_justify \
'BEGIN { RS = " " #-----------------------------#
n = 19 # Run through the variables, #
p = q = 0 # noting the longest variable #
} # name length while assigning #
{ # them to our array. In the #
len = length($1) # END section (using that #
if ( n < len ) n = len # longest length) print the #
var[++q] = $1 # variable and its value. #
} #-----------------------------#
END { j=="l" ? j="-" : j=""
for (p=1; p <= q; p++)
{
sub(/^[\n\r\t ]+/, "", ENVIRON[var[p]])
gsub(/[\n\r\t ]+/," ", ENVIRON[var[p]])
printf("%"j""n"s = %s\n", var[p], ENVIRON[var[p]])
}
}' | $PV_sort
) | $teelog # End of background export and nawk process.
# #
#---------------------------------------------------------------#
return 0
fi # if [ $# -gt 0 ]; then
#------------------------------------------------------------#
# Reaching here means something is amiss. #
#------------------------------------------------------------#
if [ .${SHLIB} = . ]; then
SHLIB=/usr/local/scripts; export SHLIB
fi
. $SHLIB/email_msg.sh # Calls $SHLIB/exit.sh
if [ $# -lt 1 ]; then
EMAIL_MSG "ERROR: $PV_ID" \
"${sp}Insufficient args!" \
"${sp}Usage: $PV_name var ..." \
"${sp}Function terminated--processing continues."
return 1
fi
} # "PV_" prefix identifies this function's variables.
fi
#======================================================================#
# D O C U M E N T A T I O N #
#======================================================================#
# #
# Author: Bob Orlando #
# #
# Date: March 26, 1998 #
# #
# Program ID: print_vars.sh #
# #
# Usage: PRINT_VARS -s -l variable ... #
# #
# -l = left-justify variable names. #
# -s = sort var names before printing. #
# variable = one or more variable names #
# --WITHOUT DOLLAR-SIGN(s)--that #
# are to be displayed in a neat #
# tabular format. #
# #
# Purpose: Print variables (variable name and value) in a neat #
# tabular form. #
# #
# Description: Unassigned or NULLed variables are displayed as blank. #
# #
# Examples: PRINT_VARS active_status_file working_dir log_dir #
# Default list .. #
# | active_status_file = $tmp/print_vars_curr_status #
# | working_dir = /usr/sis/v_1_1/sh_lib #
# | log_dir = /usr/local/logs #
# #
# PRINT_VARS -s active_status_file working_dir log_dir #
# Sorted list .. #
# | active_status_file = $tmp/print_vars_curr_status #
# | log_dir = /usr/local/logs #
# | working_dir = /usr/sis/v_1_1/sh_lib #
# #
# PRINT_VARS -l active_status_file working_dir log_dir #
# Left-justified list .. #
# | active_status_file = $tmp/print_vars_curr_status #
# | working_dir = /usr/sis/v_1_1/sh_lib #
# | log_dir = /usr/local/logs #
# #
# Globals: No global variables are assigned in this function. #
# "PV_" prefix identifies local function variables. #
# #
# Exit_status: Returns with failure (1) for error (e.g. user supplies #
# an invalid argument). Otherwise, returns 0 (success). #
# #
# Calls: EMAIL_MSG library function. #
# #
# Notes: .................................................... #
# .................................................... #
# #
# Modified: 2004-09-17 Bob Orlando #
# v1.15 * Change $log and $teelog assignments #
# from #
# if [ ."$log" = . ]; then #
# log=$name_root.log #
# [ ."$teelog" = . ] && teelog="cat" #
# fi #
# to #
# [ ."$log" = . ] && log=$name_root.log #
# [ ."$teelog" = . ] && teelog="cat" #
# #
#----------------------------------------------------------------------#
|