How to know if a specific command (e.g. bc) is available in an original Ubuntu?

Little Girl littlergirl at gmail.com
Wed Mar 3 15:10:22 UTC 2021


Hey there,

孙世龙 sunshilong wrote:

>How to know if a specific command (e.g. bc) is available in an
>original Ubuntu 16.04?

There are lots of ways to do it. Some of them are here:

https://stackoverflow.com/questions/592620/how-can-i-check-if-a-program-exists-from-a-bash-script

And here:

https://stackoverflow.com/questions/7522712/how-can-i-check-if-a-command-exists-in-a-shell-script

My favorite is below, with COMMAND representing the name of the
command you're checking for:

if type "COMMAND" &> /dev/null; then echo "YES"; else echo "NO"; fi;

You would replace COMMAND with bc to check for your example command:

if type "bc" &> /dev/null; then echo "YES"; else echo "NO"; fi;

-- 
Little Girl

There is no spoon.




More information about the ubuntu-users mailing list