Good question. It works fine for me. You should always specify evaluated variables (
"$X" instead of
$X ); perhaps this fixes your error.
But I suggest using the result of a python script instead of its output:
#!/bin/bash if python -c 'import sys; sys.exit(1 if sys.hexversion<0x03000000 else 0)' then echo "Fine!" fi
If you like to stay completely in the shell, you can also use the --version option:
case "$(python --version 2>&1)" in *" 3."*) echo "Fine!" ;; *) echo "Wrong Python version!" ;; esac
Perhaps this is more readable.
source share