From the terminal verify if python 3 is installed
Interactive shell
Simply run python3 --version
. You should get some output like Python 3.8.1
if Python 3 is installed.
Shell script
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.
execute the following command.
which python3
and check the exit status of the command $?
. it will be 0 if user has python 3 installed, 1 otherwise.
You can check it with regular expression match, on the "python3 -V" output.
For example:
[[ "$(python3 -V)" =~ "Python 3" ]] && echo "Python 3 is installed"