#! /bin/sh # Name: hd_scanenv # Usage: hd_scanenv script variable-name # Description: Utility to read the value of an environment or shell # variable from a script. It sources (.) the named shell script, # then echoes the value of the named environment variable. # Purpose is so that the caller can determine the value of one # variable set by the script without sourcing it and thus making # more changes to the caller's environment. #------------------------------------------------------------------------------- # Name of this script, for output script_name=`echo $0 | sed 's%.*/%%'` # Check command line if [ $# -ne 2 ]; then echo "$script_name ERROR: Need two arguments." >&2 echo "$script_name usage: $script_name sh-file env-var" >&2 exit 1 fi if [ ! -f $1 ]; then echo "$script_name ERROR: First argument must be a file name containing Bourne shell commands." >&2 exit 1 fi # Source the script given by the first argument . $1 # Report the value of the variable named in the second argument eval echo \$$2 # $Log: hd_scanenv,v $ # Revision 1.1 2002/08/07 20:27:05 peachey # Utility to read environment variables out of shell scripts by sourcing # them in a subshell, then echoing the variable. #