I thought I was all clever because I figured out a good technique of
making configuration files executable with #!. But apparently I
was not so clever.
On FreeBSD I got this working nicely:
#!/usr/bin/env paster exe serve
The exe told paster that it should expect the shebang setup
(config file follows, etc). And while putting paster itself as
the command didn't work, /usr/bin/env parsed everything
nicely for me (and since paster itself uses a shebang line to be
executable, only /usr/bin/env was willing to recursively interpret
that).
paster would then end up seeing an argv like ['paster', 'exe',
'serve', config_file, extra_args...] where extra_args were any
arguments you passed on the command line. The environmental variable
_ would be set to config_file.
Usually something that seems sensible on FreeBSD will work on Linux;
in comparison to BSD tools, the GNU tools (standard on Linux)
generally favor sensibility over backward compatibility, and FreeBSD
seems very sensible in this case. I could only expect more
sensibility on Linux, right?
Sadly, no. /usr/bin/env parses that as a request to run "paster
exe serve" -- i.e., a file with embedded spaces. Sigh. It does
still set _, and passes extra arguments. But I still want to know
when I'm in a shebang environment, so paster can respond
accordingly, and I'm not sure how to detect that.
When environ['_'] != sys.argv[0]? Is that reliable? Is there another
way to detect this? Any hints for MacOS (like FreeBSD?) and/or Solaris
(like stupid Linux?)