Bjarni |grep -i tech on Nostr: Yesterday, for reasons best left unstated, I invented a technique for combining #bash ...
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()
Published at
2025-04-25 11:07:03 UTCEvent JSON
{
"id": "bba6cdd6a69dcd2b2033fc2035c2388c690cdc77121deff4f2f10e22975a2eeb",
"pubkey": "6af25204f7bb6353edfc2a234cc27d70c9e6fd2704f0539195731006c9690950",
"created_at": 1745579223,
"kind": 1,
"tags": [
[
"proxy",
"https://floss.social/@HerraBRE/114398279974025867",
"web"
],
[
"t",
"bash"
],
[
"t",
"python"
],
[
"proxy",
"https://floss.social/users/HerraBRE/statuses/114398279974025867",
"activitypub"
],
[
"L",
"pink.momostr"
],
[
"l",
"pink.momostr.activitypub:https://floss.social/users/HerraBRE/statuses/114398279974025867",
"pink.momostr"
],
[
"-"
]
],
"content": "Yesterday, for reasons best left unstated, I invented a technique for combining #bash and #Python into a single file.\n\nThe motivation was to have something a bit more powerful than the #! to decide which installed Python to use. \n\nThe magic is in line two:\n\n#!/bin/bash\n\"\"\"\"true\"\n# bash sees this, python ignores it\nif [ -e /path/to/file ]; then\n exec python3 \"$0\" \"$@\"\nelse\n echo \"OMG, something is missing\"\n exit 1\nfi\n\"\"\"\n# begin python fun!\nfrom thing import python_stuff\npython_stuff()",
"sig": "ef41654d569414f4f9fb22f887f71f6b303bb8ab4d1b7088d869c5b2d9fd47701ffef4c3b483229f619a5276f6faa5cb07f2f1b533a3b5f1fe4d5fef8a541b68"
}