I have a script file myfile.sh
and contains the following
#! /bin/bash
set -e
MYVAR=`cat $1 | python -c 'import os`'
The question is, how I can make a condition to use python3 if python3 is installed or in other word(python is > 3) and use python if the installed version of is < 3 something like:
#! /bin/bash
set -e
# CONSIDER THIS SUDO CODE
if 'python3 --version' !== 'command not found or something null'; then # SUDO CODE
PYTHON=python3
else
PYTHON=python
fi
MYVAR=`cat $1 | PYTHON -c 'import os`'