#! /bin/sh # # $TOOLS/replpath # # Replaces any old reference of the environment variable (whose name is passed # in $1) in the PATH with a new definition (specified in the $2 parameter). # (The old definition must be contained in the substitution of the $1 param). # # If there is no matching old reference of the environment variable in the # PATH, the new definition (specified in the $2 and $3 parameters) will be # appended to the existing PATH. # # Defines the $1 environment variable name having the new value specified in # the $2 parameter. # # The calling script must execute this in the context of the parent's shell, # so the environment variables that are defined are accessible by the parent. # Example: # set ORACLE_HOME $NEWORACLE_HOME /bin # . $TOOLS/replpath # # =====> Note that this will change the parent's $1, $2, and $3 variables. # # Last Change 02/20/97 by Brian Lomasky to include calling example. # Last Change 02/17/97 by Brian Lomasky to rename replace_path to replpath. # Last Change 06/19/96 by Brian Lomasky to include $3 param and surrounding # colons in the PATH specification, to # fix problem when $ORACLE_HOME translates # to a subset of the $DBA or $TOOLS # emnvironment variables set +u # Do not treat unset variables as an error OLDVAR=`eval echo \\$"$1"` # Get the substitution of the substituted $1 if [ "$3" != "" ] then P3=$3 else P3="" fi set -u # Treat unset variables as an error case "$OLDVAR" in "") OLDVAR=PLUGH ;; # This makes it so that null OLDVAR can't match esac # anything in next case statement case "$PATH" in *:$OLDVAR$P3:*) PATH=`echo $PATH|sed "s;:$OLDVAR$P3:;:$2$P3:;g"`;;#Old match? *:$2$P3:*) ;; # If already the new definition? *:) PATH=${PATH}$2$P3: ;; # If path ends in a colon? "") PATH=$2$P3: ;; # If path is null? *) PATH=$PATH:$2$P3: ;; # If none of the above? esac export PATH eval $1=$2 # Define the new environment var