-2

Code:

iIMSI=`sqlplus -s ${APP_ORA_USER}/${APP_ORA_PASS}@${APP_DB_INST} << EOF
SET HEAD OFF PAGESIZE 0 LINESIZE 1000 TRIMOUT ON TIMING OFF
select resource_value from agd1_resources where resource_type='3'
and subscriber_id in (select subscriber_id from agd1_resources where resource_value='$sSUBSCRIBER');
exit;
EOF`

if [ "$iIMSI" = "no rows selected" ]; then
echo hello
else echo elseblock
fi

Question:

I'm giving sSUBSCRIBER value which is not present in table, so the query result is 'no rows selected' which I stored in iIMSI.

Why is my if condition is not working (it is always running the else block)?

  • 1
    Is that text actually stored in the variable, or is it printed to the terminal? – Kusalananda Mar 12 '18 at 8:12
  • 1
    What does printf '%s\n' "$iIMSI" | sed -n l output? – Stéphane Chazelas Mar 12 '18 at 8:44
0

To check, if you have the expected value in the variable, please insert an echo "$iIMSI" in the line above the if-statement.

I tried the following script

$ cat test.sh
#!/bin/bash

iIMSI="no rows selected"
if [ "$iIMSI" = "no rows selected" ]; then
echo hello
else echo elseblock
fi

and it worked as expected.

$ ./test.sh 
hello

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.