loading...

re: Bash Brackets Quick Reference VIEW POST

TOP OF THREAD FULL DISCUSSION
re: the $( COMMAND )$? trick is a very bad one. Please don't advertise it, it basically NEVER works as you intend it to.
 

Not sure what your experience is, but mine is that it works pretty much exactly as one would reasonably expect. It's functionally equivalent to executing something like:

<COMMAND>

if [[ $? ]]
then
…

But without any shell-linters bitching about using an inefficient execution-form.

That said, you need to be familiar with what the subshelled-command's likely outputs are going to be. Which is to say:

  • If the subshelled-command has an output other than just an exit code, you need to suppress it. Some commands have a built-in "quiet" option; for those that don't, you can suppress by redirecting output to /dev/null. Failing to suppress output will tend to cause evaluation-logic to evaluate as a string of <COMMAND_OUTPUT><COMMAND_EXITCODE> rather than an integer of <COMMAND_EXITCODE>.
  • Similarly, if you care to handle more than a -eq 0 or -ne 0 output, you need to be familiar enough with the given command's possible exit-codes to set up the appropriate handlers you might want/need.

Some comments have been hidden by the post's author - find out more

code of conduct - report abuse