if command; then ...
evaluates the exit status of
command. 0 is success (evaluates the condition as true).
First of all:
[ is (almost) identical with
test, hence it expects the
command string to comply with its syntax.
if [ $(command) ]; then ...
evaluates the string containing the output of
command. In most cases it will not work - see the example below.
[ command ] && ..
grep -l "mail" "file" will be interpreted like this:
grep - a string
-l - unary operator returning the length of the following string
"mail" - a string, will be passed as an argument to the
"file" - a string
Depending on implementation you will get slightly different errors, because the above is asking
[ to evaluate a sequence consisting of a string, a number and another string, without any operators. By default
[ (as well as
test) is a shell built-in, you can compare the error messages with the standalone binary (usually