Check the value of a variable

#!/bin/sh
 echo "Running Script to capture ORACLE Erros"
 # Change Directory to the actual logs path
 cd /home/nv8510/lognew
 err_var=`grep -in "ORA-" *`
 
 if[-n $var] then
 echo "THESE ARE THE ORACLE ERROR OCCURED"
 echo "$err_var"
 echo "************************************************************************"
 else
   echo "No erros"
 fi

In the abv script i want to chk if the variables exits then i will display all the error msg and if not it will display No errors , but i ma getting this error will executing the script :

./nvora2.sh: line 8: if[-n ]: command not found

how to chk if a varible is set or not , please help.

Consider [ ] as programs, not brackets, to understand how their syntax works. "[-n" is not the same program as "[" "-n".

You need spaces.

if [ -n "$var" ]
then
...
fi

Running Script to capture ORACLE Erros

./nvora2.sh: line 8: if[ -n ]: command not found

---------- Post updated at 05:03 PM ---------- Previous update was at 05:00 PM ----------

#!/bin/sh
echo "Running Script to capture ORACLE Erros"
# Change Directory to the actual logs path
cd /home/nv8510/lognew
err_var=`grep -in "ORA-" *`
if[ -n "$var"] then
echo "THESE ARE THE ORACLE ERROR OCCURED"
echo "$err_var"
echo "************************************************************************"
else
        echo "No erros"
fi

I am trying the ab now and getting this erro :

Running Script to capture ORACLE Erros

./nvora2.sh: line 8: if[ -n ]: command not found

THESE ARE THE ORACLE ERROR OCCURED
************************************************************************

./nvora2.sh: line 14: syntax error near unexpected token `else'
./nvora2.sh: line 14: `else'

You forgot more spaces again.

"if[" is not the same command as "if" "["

oh got it , i m new to this thts y :

so lets go now to nest step , i m getting this error now

Running Script to capture ORACLE Erros

./nvora2.sh: line 14: syntax error near unexpected token `else'
./nvora2.sh: line 14: `else'

******************************

#!/bin/sh
echo "Running Script to capture ORACLE Erros"
# Change Directory to the actual logs path
cd /home/nv8510/lognew
err_var=`grep -in "ORA-" *`
if [ -z "$var" ] then
echo "THESE ARE THE ORACLE ERROR OCCURED"
echo "$err_var"
echo "************************************************************************"
else
        echo "No erros"
fi

not sure what is the syntax error in this.

If your "then" is on the same line as the "if", you need a semi-colon after the closing bracket of the if statement:

if [ -z "$var" ]; then

P.S. Please use code tags and indentation to make your code easier to read.

either use

if [ -z "$var" ]; then

or

if [ -z "$var" ] 
then

yupppie , thanks evry one.