shebanged script not executed right - wth
Date: Sat, 09 Aug 2025 05:39:12 UTC
I have the following setup, which works as intended on multiple quite
different penguin systems:
$ ls -la /opt/compat
total 16
drwxr-xr-x 2 root wheel 512 Aug 8 19:46 .
drwxr-xr-x 4 root wheel 512 Aug 3 13:17 ..
lrwxr-xr-x 1 root wheel 19 Aug 3 15:16 bash -> /usr/local/bin/bash
lrwxr-xr-x 1 root wheel 19 Aug 3 13:18 perl -> /usr/local/bin/perl
-rwxr-xr-x 1 root wheel 45 Aug 3 13:18 python3
-rwxr-xr-x 1 root wheel 1462 Aug 8 19:46 relaymail
$ cat /opt/compat/python3
#! /bin/sh
exec /usr/local/bin/python3 "$@"
$
On the penguin systems, of course it's /usr in place of /usr/local.
The idea is that scripts can put these locations for the interpreters
into their shebangs, so I can use literally the same script on
penguins and daemons.
Like relaymail here - that was supposed to be the first such script.
It is a python3 script:
$ head /opt/compat/relaymail
#! /opt/compat/python3
import sys
from argparse import (ArgumentParser, ArgumentDefaultsHelpFormatter)
import os
import subprocess
import json
CONFIG = '/usr/local/etc/relaymail.json'
BUFSIZE = 4096
Further details of relaymail aren't important.
And now the problem: this works:
$ /opt/compat/python3 /opt/compat/relaymail -h | head -3
usage: relaymail [-h] [-f ADDRESS] [-o OTHER] RCPT [RCPT ...]
simple mail submission agent with few options
but this fails mysteriously:
$ /opt/compat/relaymail -h
/opt/compat/relaymail: line 3: import: command not found
/opt/compat/relaymail: line 4: syntax error near unexpected token `('
/opt/compat/relaymail: line 4: `from argparse import (ArgumentParser, ArgumentDefaultsHelpFormatter)'
well, not completely mysteriously -- it sure seems like it's trying to
run it as a shell script ???
WTH WTH ??? IS THIS A KERNEL BUG ???
--
Ian