I have the following script which doesn't work as suppose to any ideas what;s wrong ??
cat setenv.sh
Code:
if [ -t 0 ] # Command executed from a terminal
then
ORACLE_SID=""
while [ -z "${ORACLE_SID}" ]
do
tput clear; tput rev
echo "Valid Oracle SIDs are :"
tput rmso
for SID in `cat /etc/oratab|grep -v "^#"|cut -f1 -d: -s`
do
echo " ${SID}"
done
DEFAULT=`cat /etc/oratab|grep -v "^#"|cut -d: -f1 -s|head -1`
echo "\nEnter the Oracle SID you require (def: $DEFAULT): \c"
read ANSWER
[ "${ANSWER}" = "" ] && ANSWER=$DEFAULT
export ORACLE_SID=`grep "^${ANSWER}:" /etc/oratab|cut -d: -f1 -s`
export ORACLE_HOME=`grep "^${ANSWER}:" /etc/oratab|cut -d: -f2 -s`
if [ "${ORACLE_SID}" = "" ]
then
echo "\n\n ${ANS}: Invalid Oracle SID \c"
sleep 2
fi
done
else # Set to first entry in oratab
export ORACLE_SID=`cat /etc/oratab|grep -v "^#"|cut -d: -f1 -s|head -1`
export ORACLE_HOME=`cat /etc/oratab|grep -v "^#"|cut -d: -f2 -s|head -1`
fi
export ORACLE_SID=$ORACLE_SID
export ORACLE_HOME=$ORACLE_HOME
export PATH=${PATH}:${ORACLE_HOME}/bin
#ORAENV_ASK=NO
#. ${ORACLE_HOME}/bin/oraenv
#ORAENV_ASK=
echo
echo Oracle SID is now `tput rev`$ORACLE_SID`tput rmso`, Oracle Home is `tput rev`$ORACLE_HOME`tput rmso`
echo
I am reading the oratab and asking for which sid to set to and then export ORACLE_SID and ORACLE_HOME based on input.
It does set the SID and HOME inside the script but when I echo it shows the default values. Any reason ????
./setenv.sh
HTML Code:
Valid Oracle SIDs are :
mdmop
mdmt
mdmp
Enter the Oracle SID you require (def: mdmop): mdmt
Oracle SID is now mdmt, Oracle Home is /u001/app/oracle/product/9.2/home
ga016dhd -> echo $ORACLE_SID
mdmop <== Not really set to mdmt(even if it said it is)
ga016dhd -> echo $ORACLE_HOME
/u001/app/oracle/product/9.2/home
[/home/oracle/script - oracle]