OK. I'm a bash novice, but: Though your question is clear, I'm not completely
sure I get what you ask for. This is perhaps off mark. Please tell if so.
TEST IF "echo hi > /dev/null" is success
[ `echo hi` > /dev/null ]
| | | | | |
| | | | | +--- Last test argument
| | | | +--------------- Redirect standard out to /dev/null
| | | +----------------- Backtick - End Command Substitution
| | +--------------------- echo hi
| +------------------------- Backtick - Start Command Substitution
+--------------------------- Test
If either echo or redirection fails, test fail, else success.
When a command is executed it has an exit code signifying success, 0
,
or error <> 0
. Thus if either fails everything fails.
The pattern "[ ... ]"
is not as in if (foo == bar)
, but [
is actually
a command which require ]
as last argument.
This also clarify why one need space after and before [
and ]
.