I have a bash script
foo.sh:
#!/bin/bash
echo "start"
. /path/to/bar/bar.ksh
echo "after bar"
getoravariables $1
bar.ksh (purpose is to just set oracle variables):
#!/bin/ksh
echo "b4 getora"
getoravariables () {
echo "1"
if [ $# -ne 1 ]
then
echo "2"
echo "Usage: getoravariables sid"
exit 1
fi
grep -w ${1} ${ORATAB_LOC} | grep -v "#" | sed "s/:/ /g" | read SID ORAHOME ASK
if [ $? -ne 0 ]
then
print "Error: Please enter a vaild SID and check the ${orafile} file for correct input"
return 1
fi
ps -ef|grep pmon|grep ${SID} >> /dev/null
if [ $? -ne 0 ]
then
print "Error: SID ${SID} does not seem to be started. "
return 2
fi
export ORACLE_SID=${SID}
export ORACLE_HOME="${ORAHOME}"
export ORAENV_ASK=NO
. $ORACLE_HOME/bin/oraenv > /dev/null
}
echo "after getora"
After executing foo.sh I get:
>./foo.sh validsid
start
b4 getora
after getora
So I can tell that there is no problem in simply calling the ksh script since the echo commands for "b4 getora" and "after getora" work. But there is some issue with executing the function since I don't get echo "1" or echo "2" which I would expect.
Furthermore, If I run foo.sh as a ksh script, everything works fine.
Therefore, I can assume that there is some sort of difference in syntax between the two languages that i am not catching. Can anyone assist?
UPDATE:
I added set -x at the top of my full ksh script, (what I included in my question is just a subset). I found that the script hung at a point later in my script that the function I posted:
++ echo
++ grep -v '#'
++ read VAR VALUE
(hanging here)
Those code for this part of the script is:
echo $GLOBPARFIL
grep -v "#" ${GLOBPARFIL}|while read VAR VALUE
do
export ${VAR}=${VALUE}
done
So $GLOBPARFIL doesn't get set properly. It also happens to be a variable that gets pulled in and set from getoravariables (). Output from debugging tat demonstrates this:
++ read VAR VALUE
++ export GLOBPARFIL=/home/local/par/global.par
++ GLOBPARFIL=/home/local/par/global.par
This lines up with @jlliagre answer below that declares that the the variables are not getting properly set. However, I tried the workaround with only the same undesirable result.
UPDATE 2:
Following the information and logic provided I was able to find the true source and create a workaround:
PROBLEM:
grep -v "#" ${file_location}| tr "^" " " | while read VAR VALUE
SOLUTION:
while read VAR VALUE
do
export ${VAR}=${VALUE}
done <<%
$(grep -v "#" ${file_location}| tr "^" " ")
%
I will mark as complete. But if I could receive more information on why exactly this workaround solves the problem I would greatly appreciate it.