unknown test operator

Hi,
I have the following shell script :

Nbr_BD_Link=0
Nbr_BD_Link=`
sqlplus sysadm/${PSWD}@${DB_Name} << EOF | tail -4 | head -1 2>/dev/null
set head off feedback off ;
select count(*) from dba_db_links ;
exit ;
EOF `
echo ${Nbr_BD_Link}
if [ ${Nbr_BD_Link} != "0" ] ; then

execution fail on line if [ ${Nbr_BD_Link} != "0" ] ; then

Like this :
Enter user-name: SP2-0306: Invalid option.
Check_DB_Link_BR.sh[71]: user-name:: unknown test operator
Any idea ? Any help.
Many thanks.

Try

if [[ "${Nbr_BD_Link}" != "0" ]] ; then

Are you sure that the value of this variable will ever be 0 or do you mean if the value is null in terms of empty? Because then you might want to test with -z or if value is "".

This might be interessting for you:
Bourne/Korn Shell Coding Conventions at OpenSolaris.org

Thank you. Yes primarily it was that , I mean

[ ${Nbr_BD_Link} != "0" ]

Instead of

[ "${Nbr_BD_Link}" != "0" ]

But now I can see that Nbr_BD_Link has not a numeric value , it is
Nbr_BD_Link=SQL>SQL

Any idea ?
Thank for help.

What does this echo results ? If you expect some numeric value why are you getting string as result. Does it mean you statement not functioning correctly ?

  • nilesh

From a separate thread by the same author, I concede that adding the quotes basically solved the problem