Yesterday, for reasons best left unstated, I invented a technique for combining #bash and #Python into a single file.

The motivation was to have something a bit more powerful than the #! to decide which installed Python to use.

The magic is in line two:

#!/bin/bash
""""true"
# bash sees this, python ignores it
if [ -e /path/to/file ]; then
exec python3 "$0" "$@"
else
echo "OMG, something is missing"
exit 1
fi
"""
# begin python fun!
from thing import python_stuff
python_stuff()

@HerraBRE I have decided to call this technique "the shebonk".

Because it's link a shebang, only weird!

I've added shebonk support to my forked zipapp.py, will be using to build even more portable pagekite.py bundles than before!

I wonder if this hurts my chances of getting my enhanced #zipapp merged back into upstream #CPython? :-P

#python #bash #hacks