Guys,
I need some advice on how to check a string, which may or may not have a entry.. Never really worked out how to do this.. May be a good time to learn now.
This is what i am trying to do
Run a command, to return a string
If the string is not empty , then run the if statement, otherwise ignore
How can i write the code, so it does not give out a error message. in the form of " [: argument expected"
Note that if you use the Korn shell's built-in test ( [[ ]] ) instead of the test command, you don't need to quote the variable in order for test to "see" that value:
#!/usr/bin/ksh
EFS=
# Test for null.
if [[ -z $EFS ]]; then
print a
else
print b
fi
exit 0
Output:
$ iftest
a
$
However, it's probably a good habit to quote it anyway in case you use another shell that does not work this way. Plus, it may help the person behind you maintaining your code. Actually, that's a good tip, while coding keep in mind the poor guy after you that has to maintain your code. The more time someone has to spend figuring out your tricky code, the more expensive that program has become to maintain. Make it clear and use comments assuming the person behind you is less experienced.