I have a Gruntfile with grunt-exec specified as follows:
exec: {
python_command: {
cwd: "../../",
command: 'python3.7 -c "MY_PYTHON_CODE"'
I want to use python3.7 if it exists on the system, but otherwise fall back to using python3. What's the easiest way to do this?
You could probe $PATH, if you're willing to write a loop.
This mostly sounds like a bash question: How do I find if
cmd1orcmd2is available?If you'd like to assign to a "cmd" variable, then
whichis your friend:If you're willing to live with some stderr noise, then this works:
Or tidy up the noise, if you're confident you won't see other errors: