LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   error in if statement (https://www.linuxquestions.org/questions/linux-newbie-8/error-in-if-statement-712473/)

Swapna173 03-18-2009 06:13 AM

error in if statement
 
Hi,

This is my script to catch any oracle errors.

In this, the $sqlerr returns
ORA-01017: invalid username/password; logon denied
when i specify wrong username/password

the if condition is failing. how can i resolve the issue.

The if statement gives error [: too many arguments
sqloutput=`sqlplus -s -L $dasDBConnectString @$SqlFiles/testSQLConnection.sql`
sqlerr=`echo "$sqloutput" | grep "ORA-"`
echo $sqlerr
if [ -n $sqlerr ] #sql connection error
then
Status=10
else
Status=$?
fi

tizzef 03-18-2009 06:43 AM

Hi

try this :

Quote:

if [[ -n $sqlerr ]] #sql connection error
then
Status=10
else
Status
Cheers

Kenhelm 03-18-2009 09:20 AM

There are spaces in $sqlerr so it needs to be enclosed in quotes. Try
if [ -n "$sqlerr" ]

kpraveen455 03-18-2009 09:27 AM

Any time if you get the following error means the
"if" statement has string (with spaces)

"The if statement gives error [: too many arguments"

Example:

a="hi hw are you"
if [ -n $a ] ;then <--- will give error
echo blah
else
echo blah
fi

Put in double quotes

a="hi hw are you"
if [ -n "$a" ] ;then <--- works fine
echo blah
else
echo blah
fi


All times are GMT -5. The time now is 08:42 AM.