Simple question -- what's the canonical way to test in bash whether yum or apt-get are present? I'm writing a script that will run on client machines and install unison, then create a cron job for it ...
With bash script (or sh, zsh, ksh) you could use the builtin command -v yum
and command -v apt-get
.
(yes, the command is named command)
Zero output means it isn't there, otherwise you get the commands path.
You could then use a test statement to test whether the result was null or not.
[ -n "$(command -v yum)" ]
[ -n "$(command -v apt-get)" ]
Note: A downside to @ansgar-wiechers's suggested which
is suppressing stderr for if 'yum' isn't present:
[ -n "$(which yum 2>/dev/null)" ]
An upside of which, is it isn't a shell builtin.
I'd probably use which
:
[ -n "$(which apt-get)" ]
[ -n "$(which yum)" ]
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