As "is known", a script my-script-file
which starts with
#!/path/to/interpreter -arg1 val1 -arg2 val2
is executed by exec
calling /path/to/interpreter
with 2(!) arguments:
-arg1 val1 -arg2 val2
my-script-file
(and not, as one might naively expect, with 5 arguments
-arg1
val1
-arg2
val2
my-script-file
as has been explained in many previous questions, e.g., https://stackoverflow.com/a/4304187/850781).
My problem is from the POV of an interpreter developer, not script writer.
How do I detect from inside the interpreter
executable that I was called from shebang as opposed to the command line?
Then I will be able to decide whether I need to split my first argument
by space to go from "-arg1 val1 -arg2 val2"
to ["-arg1", "val1", "-arg2", "val2"]
or not.
The main issue here is script files named with spaces in them. If I always split the 1st argument, I will fail like this:
$ my-interpreter "weird file name with spaces"
my-interpreter: "weird": No such file or directory