I am writing a shell script, and before the script runs I want to verify that the user has Python 3 installed. Does anyone know or have any ideas of how I could check that, and the output be a boolean value?
Simply run python3 --version
. You should get some output like Python 3.8.1
if Python 3 is installed.
You can use the command
or type
builtins:
command -v python3 >/dev/null 2>&1 && echo Python 3 is installed # POSIX-compliant type -P python3 >/dev/null 2>&1 && echo Python 3 is installed # Bash only
Using which
is not recommended as it requires launching an external process and might give you incorrect output in some cases.
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