Hacker News new | ask | show | jobs
by warvariuc 1682 days 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
    ":"""
4 comments

Is it still bash code if you're running /bin/sh?
Not for shellcheck(1). It warns about bashisms if it sees `/bin/sh` after the hash-bang.
Presumably not, it depends on your system. Some people symlink sh to bash.
Which(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.
That approach will break now that python 3.10 is out
Or, it won't break your code if you haven't tested in 3.10 yet ;)
don't you want to go in descending order?