Using Terminal, what's the easiest way to determine if a binary named dcmdump is installed on the user's system? If installed I need to know its location (e.g. /usr/local/bin) and if its not installed then I'd like the Terminal to echo FALSE.
I know very little Terminal script but typing:
command -v dcmdump
Outputs the directory dcmdump is installed in (if installed - which is great) but nothing is echoed if its not (I want it to echo the string FALSE)
You can use this:
$ which dcmdump 2>/dev/null || echo FALSE
Here is how it works:
||) of two commands. The left-hand-side of the OR is the command which dcmdump 2>/dev/null, the right-hand-side is echo FALSE.which NAME looks for an executable named NAME in your current shell $PATH. If it finds one, it prints its absolute path to the standard output and exits with a status indicating “success”, otherwise, it might or might not print an error message to the standard error output and returns a status indicating “failure”.which's error message but our own, we redirect which's standard error output to the black hole /dev/null with the 2>/dev/null part.echo TEXT simply outputs TEXT to the standard output. If you wanted FALSE to be printed to the standard error output, you could redirect it using echo FALSE >&2.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With