9 ms·
Or #!/bin/sh """:" # bash code here; finds a suitable python interpreter and execs this file. for pyver in 3.6 3.7 3.8 3.9; do which py
by warvariuc 5y ago
Or
#!/bin/sh
""":"
# bash code here; finds a suitable python interpreter and execs this file.
for pyver in 3.6 3.7 3.8 3.9; do
which python$pyver > /dev/null 2>&1 && exec python$pyver "$0" "$@"
done
echo "No appropriate python interpreter found." >&2
exit 1
":"""
- ByThyGrace 5y agoIs it still bash code if you're running /bin/sh?
- dagw 5y agoThat approach will break now that python 3.10 is out
- mattnewton 5y agoOr, it won't break your code if you haven't tested in 3.10 yet ;)
- cozzyd 5y agodon't you want to go in descending order?
- gnubison 5y agoWhich(1) doesn’t necessarily return a non-zero exit code if it can’t find a program. Instead, the portable alternative for scripts is command -v.