in reply to Re^7: shebang anomaly
in thread shebang anomaly
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^9: shebang anomaly
by afoken (Chancellor) on Apr 23, 2018 at 19:21 UTC | |
I think you want to replace "shell" with "kernel". I suppose it could be in libc, but I'm certain it's not in /bin/sh, except for cygwin. No, sorry, shells have to have a fallback mechanism if your O/S claims POSIX compatibility. See Re^2: Shebang behavior with perl. It's not in libc. But yes, usually the kernel extracts the interpreter and the argument (note: singular) from the shebang line. Alexander
-- Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-) | [reply] |
by jeffenstein (Hermit) on Apr 24, 2018 at 10:02 UTC | |
The linked page in your other response only has this reference to the shebang line: The shell reads its input from a file (see sh), from the -c option or from the system() and popen() functions defined in the System Interfaces volume of POSIX.1-2017. If the first line of a file of shell commands starts with the characters "#!", the results are unspecified.The last I checked, /bin/sh on Solaris wasn't even POSIX compliant, so you can't count on that. So, to go back to the OP, I would say for maximum portability to write a bourne shell (/bin/sh) wrapper to run it, or give this snippet from perlrun a try to avoid a wrapper:
| [reply] [d/l] [select] |
by afoken (Chancellor) on Apr 24, 2018 at 22:46 UTC | |
The linked page in your other response only has this reference to the shebang line It's a little bit hidden in 2.9.1 Simple Commands, Command Search and Execution, number 2:
What happens here is this: The rationale for this is that ancient shell scripts did not have a #! line. More details ... Demo:
Note that in the second attempt to run demo, my login shell (indicated by the leading "-") complains about the demo script specifying a bad interpreter. In the third attempt, it complains about wrong permissions on the script. And now, the non-obvious trick: I copied an old DOS executable (defrag.exe) to /tmp.
No, my Linux did not execute defrag.exe. It can't, I don't have any emulator or the like set up for DOS executables. Bash complains if defrag.exe is not executable, but when it is executable and the kernel still had complained about an unknown executable behind the scenes, the little demo script is executed as a shell script. Alexander
-- Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-) | [reply] [d/l] [select] |
by jeffenstein (Hermit) on Apr 25, 2018 at 13:40 UTC |