The case of the supersized shebang
The case of the supersized shebang
Posted Feb 19, 2019 4:34 UTC (Tue) by anguslees (subscriber, #7131)In reply to: The case of the supersized shebang by pabs
Parent article: The case of the supersized shebang
It's much less common with the "modern" scripting languages (python/ruby), since they're usually treated as full-featured programming environments quite separate to any functionality they have as an interactive shell experience.
Guile is pretty close, with a "\" "meta switch" and defining #! ... !# as comment delimiters. You can do this:
#!/usr/local/bin/guile \ -e main -s !# (define (main args) (display "hello, world!") (newline))Related, but different:
Many other "scripting" languages use #
as a comment character and can do some similar shell bootstrap hack too. Most of these are used to lookup the language interpreter in the path, knowing only that /bin/sh
exists.
For some reason I never understood, the modern world has decided it is better to assume that /usr/bin/env
exists instead (using env in this way still doesn't allow multiple args, unless you're using freebsd's env -S
magic arg - also in coreutils 8.30 apparently).
Perl:
#!/bin/sh #! -*-perl-*- eval 'exec perl -x -wS $0 ${1+"$@"}' if 0; # perl code continues here
Python:
#!/bin/sh ''':' if type python2 >/dev/null 2>/dev/null; then exec python2 "$0" "$@" else exec python "$0" "$@" fi ''' # Python code continues here(and similar hacks for awk, ruby, etc)
Posted Feb 19, 2019 10:14 UTC (Tue)
by dottedmag (subscriber, #18590)
[Link] (4 responses)
Posted Feb 19, 2019 11:08 UTC (Tue)
by Baughn (subscriber, #124425)
[Link]
Posted Feb 19, 2019 13:58 UTC (Tue)
by DrHyde (guest, #130508)
[Link] (2 responses)
Posted Feb 19, 2019 16:01 UTC (Tue)
by dbaker (guest, #89236)
[Link] (1 responses)
Posted Feb 19, 2019 17:21 UTC (Tue)
by DrHyde (guest, #130508)
[Link]
Posted Feb 19, 2019 13:23 UTC (Tue)
by smurf (subscriber, #17840)
[Link] (2 responses)
Posted Feb 19, 2019 16:16 UTC (Tue)
by tux3 (subscriber, #101245)
[Link] (1 responses)
Posted Feb 19, 2019 16:17 UTC (Tue)
by tux3 (subscriber, #101245)
[Link]
The case of the supersized shebang
The case of the supersized shebang
The case of the supersized shebang
The case of the supersized shebang
The case of the supersized shebang
The case of the supersized shebang
The case of the supersized shebang
It seems python is happy as long as it's the first line actually executed, though the error message is confusing.
The case of the supersized shebang