Useful for resolving python path(s) in FreeBSD, because ports installed python contains the major AND minor version number in its path.
#!/bin/sh
#
# Show installed python(s) details
#
# Useful for resolving python path(s) in FreeBSD, because Ports installed
# Python contains the major AND minor version number in its path.
#
# In other words, `command -v python` or `which python3` would fail, even
# if python (or python3) is installed.
#
# Ex: `/usr/local/bin/python3.8`... instead of just `/usr/local/bin/python` or `/usr/local/bin/python3`
#
# Author....: Jon LaBelle
# Date......: May 25, 2021
# License...: MIT
#
#
py_prefix=/usr/local/bin
# shellcheck disable=SC2010
py_versions="$(ls ${py_prefix} | grep python | perl -ne 'print if m/^python([0-9]+?[\.]?[0-9]?[0-9])?$/m')"
result=$?
if [ $result -ne 0 ]; then
echo "Python not installed." >&2
exit $result
fi
for py_version in $py_versions; do
py_interpreter="$(command -v "${py_version}")"
result=$?
if [ $result -ne 0 ]; then
echo "Python interpreter path not found." >&2
exit $result
fi
echo "Installed python version...: ${py_version}"
echo "Python interpreter path....: ${py_interpreter}"
echo "Shebang directive..........: #!${py_prefix}/${py_version}"
echo ""
done
exit $result