In one of my previous threads, someone suggested not to use backticks. When I googled, I came to know that back ticks are deprecated instead $() should be used. But I face issue while using $().
Note: I used echo of the sql just to debug.
The following is the code
#!/bin/ksh
#set -x
ScriptDir=$(dirname $0)
. ${ScriptDir}/setEnv.sh
VAL=X
echo "\$(sqlplus -s $user_name/$user_pwd@$database_name <<EOF
set pagesize 0 LINESIZE 1000 feedback off verify off heading off echo off
select count(1) from dual where dummy = '$VAL';
EXIT;
EOF)"
REC_EXIST=$(sqlplus -s $user_name/$user_pwd@$database_name <<EOF
set pagesize 0 LINESIZE 1000 feedback off verify off heading off echo off
select count(1) from dual where dummy = '$VAL';
EXIT;
EOF)
echo "CHECK RUN STATUS"
run_status=$?
echo "RUN STATUS : $run_status"
echo "REC_EXIST : $REC_EXIST"
if [ $REC_EXIST == 0 ] ;then
echo "No Records : $REC_EXIST"
else
echo "Records exists: $REC_EXIST"
fi
The above code works fine as long as I use back tick. When I replace backticks with $(), I encounter the following error
$(sqlplus -s xxxxxxx/xxxxx@xxxxxxx <<EOF
set pagesize 0 LINESIZE 1000 feedback off verify off heading off echo off
select count(1) from dual where dummy = 'X';
EXIT;
EOF)
CHECK RUN STATUS
RUN STATUS : 0
REC_EXIST : select count(1) from dual where dummy = "$VAL"
*
ERROR at line 1:
ORA-00904: "$VAL": invalid identifier
test.sh[XX]: count(1): unknown test operator
Records exists: select count(1) from dual where dummy = "$VAL"
*
ERROR at line 1:
ORA-00904: "$VAL": invalid identifier
Records exists: select count(1) from dual where dummy = "$VAL"
*
ERROR at line 1:
ORA-00904: "$VAL": invalid identifier
By using $() I got good results for other scripts. Can anyone explain what went wrong.
Appreciate your response