I am trying to check if a multi-word command output starts with a certain string. For example, here I am trying to check the default Python version. Here is my current code that does not work:
# handle default python version
pycmd="python"
if [[ "$($pycmd --version)" = "Python 2"* ]]
then
echo "It is Python 2"
pycmd="python3"
else
echo "It is Python 3"
fi
What can I do to achieve my goal (i.e., checking the default Python version and change $pycmd
if needed.) The above code always goes to the else
block even if I change the string to "Python 3"*
. Also, I don't want to print the output of the Python version command.