Skip to content

Instantly share code, notes, and snippets.

@FRex
Created September 23, 2024 00:52
Show Gist options
  • Save FRex/f30151a5e3e01d0bc343b70f5c08acee to your computer and use it in GitHub Desktop.
Save FRex/f30151a5e3e01d0bc343b70f5c08acee to your computer and use it in GitHub Desktop.
#!/bin/bash
if [[ $# -eq 0 ]]; then
echo "no version argument was given" >/dev/stderr
exit 2
fi
ver="$1" # save version
shift # and remove it form the argument list
for pythonexepath in /d/anypython/python-*-embed-win32/python.exe; do
# try match exactly and the dotless version with regex, so for example
# ver=3.5 and ver=35 will both match python-3.5.0-embed-win32
dotlesspath=${pythonexepath//./}
if [[ "$pythonexepath" =~ /python-$ver ]] || [[ "$dotlesspath" =~ /python-$ver ]]; then
"$pythonexepath" "$@" # call first matching python with the rest of arguments
exit # exit with the same status as python exited with
fi
done
# print error, all available exes, and exit with non-zero status
echo "could not find python for $ver"$'\n'"available versions:" >/dev/stderr
for pythonexepath in /d/anypython/python-*-embed-win32/python.exe; do
echo "$pythonexepath"
done | rev | cut -f2 -d/ | rev >/dev/stderr
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment