when i run a select query in database, it will return the objid based on the condtion. If there is no objid tht meets the condition, I will not get any value returned and the variable will hold nothing... so now how to chk tht the variable is blank or not. I tried the below piece of code:
if [ -z $objid ]; then
echo "No objid returned"
else
<do this>
.
.
.
fi
but the above code throws the following error:
test: argument expected.
Or else please let me know how to check whether the variable holds the numerical or not, this will also serve my purpose.
The form "[ ]" is essentially calling the external "test" command, and thus everything is evaluated by the shell first. That's why you get "test: argument expected" when $objid is NULL, since the expression evaluates to "[ -z ]".
When using "[ ]", you really need to quote all values/variables. But, you can use the super-secret double bracket:
if [[ -z $myvar ]]; then.....
WIth the double-brackets, the test is a shell builtin. So nothing needs to be quoted, since it is not evaluated prior to being tested. Plus, you will save dozens of milliseconds by avoiding an external program.