I am writing my first shell script. In my script I would like to check if a certain command exists, and if not, install the executable. How would I check if this command exists?
if # Check that foobar command doesnt exist
then
# Now install foobar
fi
In general, that depends on your shell, but if you use bash, zsh, ksh or sh (as provided by dash), the following should work:
For a real installation script, you’d probably want to be sure that
typedoesn’t return successfully in the case when there is an aliasfoobar. In bash you could do something like this: