We are talking about the shell, not some bastardization of execve(), that sees 
it's not a directly loadable process image so treats it as a script. For those 
shells implementing shebang as an extension it is still them piping the body of 
the script after the shebang line, without any token expansion, to an alternate 
interpreter via an exec() of some sort. Second, conforming applications can not 
rely on unspecified behaviors, so having a use beyond that specified makes the 
shell nonconforming. Calling it out like that simply acknowledges a lot of 
shell implementations choose to make themselves nonconforming, I do not see it 
as an endorsement or allowance. The requirement explicitly specified behavior 
shall be implemented as specified takes priority. Some conforming script 
authors may simply want the first line to be a#!!!! IMPORTANT USAGE NOTE 
!!!!headline, or similar, not want a utility named "!!!" to be exec'd.
What the standard does allow as an extension, and I would support adding to the 
standard, is adding an option to turn off token expansion in here-doc bodies, 
and back on, via set. This allows the effect of shebang to be accomplished 
anywhere in a script, at the expense of a few extra characters for the here 
delimiter and set commands, without any other changes to tokenizing or the 
grammar. 
 
  On Sun, Apr 11, 2021 at 12:15 PM, Harald van Dijk<a...@gigawatt.nl> wrote:   
On 11/04/2021 17:09, shwaresyst via austin-group-l at The Open Group wrote:
> No, it's not nonsense. The definition of comment has all characters, 
> including '!', shall be ignored until newline or end-of-file being 
> conforming. Then tokenization which might discover an operator, keyword 
> or command continues. This precludes "#!" being recognized as any of 
> those. There is NO allowance for '!' being the second character as 
> reserved for implementation extensions.

This is wrong on two counts. The first is that you're assuming that this 
will be interpreted by a shell. If execve() succeeds (and the #! line 
does not name a shell), it will not be interpreted by a shell at all, 
and the shell syntax for comments is irrelevant. The second is about 
what happens when it does get interpreted by a shell: POSIX allows 
shells to treat files starting with "#!" specially: "If the first line 
of a file of shell commands starts with the characters "#!", the results 
are unspecified."

Cheers,
Harald van Dijk
  
        • Re: [She... Harald van Dijk via austin-group-l at The Open Group
          • Re: ... Joerg Schilling via austin-group-l at The Open Group
        • Re: [She... Robert Elz via austin-group-l at The Open Group
          • Re: ... Harald van Dijk via austin-group-l at The Open Group
          • Re: ... Robert Elz via austin-group-l at The Open Group
          • Re: ... Harald van Dijk via austin-group-l at The Open Group
        • Re: [She... Joerg Schilling via austin-group-l at The Open Group
  • Re: [Shell Command La... Robert Elz via austin-group-l at The Open Group
    • Re: [Shell Comma... shwaresyst via austin-group-l at The Open Group
      • Re: [Shell C... Harald van Dijk via austin-group-l at The Open Group
        • Re: [She... shwaresyst via austin-group-l at The Open Group
          • Re: ... Harald van Dijk via austin-group-l at The Open Group
          • Re: ... Joerg Schilling via austin-group-l at The Open Group
          • Re: ... Chet Ramey via austin-group-l at The Open Group
        • Re: [She... Robert Elz via austin-group-l at The Open Group
      • Re: [Shell C... Joerg Schilling via austin-group-l at The Open Group
      • Re: [Shell C... Joerg Schilling via austin-group-l at The Open Group
        • Re: [She... shwaresyst via austin-group-l at The Open Group
        • Re: [She... Robert Elz via austin-group-l at The Open Group
          • Re: ... Joerg Schilling via austin-group-l at The Open Group
          • Re: ... Chet Ramey via austin-group-l at The Open Group

Reply via email to