AraR87
1
Guys,
Please help me on the below
sample.cfg
var=NULL
sample.sh
#!/bin/sh
. /sample.cfg
if [ $var -eq NULL ];then
1 st command here
else
2 nd command here
fi
Now i want the first command to be exectuted if the variable is NUll. If i specify the variable name, the second command to be executed.
Please advise
Thanks
put NULL in double quotes.. and if you are equating string better use = than -eq
zaxxon
3
#!/bin/sh
. ./sample.cfg
if [ "$var" = "NULL" ]; then
echo first
else
echo second
fi
exit 0
Be aware:-
#!/bin/bash
nulltest()
{
if [ ${#var} -eq 0 ]
then
echo "NULL, empty string..."
else
echo "Not an empty string..."
fi
}
var=""
nulltest
var=NULL
nulltest
Gives results:-
Last login: Thu Jul 11 07:58:36 on ttys000
AMIGA:barrywalker~> ./null.sh
NULL, empty string...
Not an empty string...
AMIGA:barrywalker~>