• Prevalence of #! (was: [ANN] KornShell 93u+m/1.0.0)

    From Geoff Clare@21:1/5 to Ed Morton on Fri Aug 5 14:07:04 2022
    Ed Morton wrote:

    On 8/4/2022 4:06 PM, Dan Espen wrote:
    [email protected] writes:

    On Thu, 04 Aug 2022 20:28:06 GMT
    [email protected] (Scott Lurndal) wrote:
    [email protected] writes:
    Should. How often do you see it in practice?


    100%. As noted in other posts, we use a number of different interactive >>>> shells, and a number of scripting languages (tcsh, ksh, bash, perl, python,
    tcl, et alia). And that's been true for every POE I've worked in for
    the last three plus decades (system or processor OEMs primarily).

    Don't believe you. I've seen more scripts than I can count that didn't
    have the hash bang at the start. No idea what a she-bang is. Sounds like >>> a service for sailors in a port.

    Well, where I worked, every shell script we shipped to customers had
    a hash bang. Feel free to not believe me too.


    Likewise, 100% of the shell scripts shipped to customers or used as a
    tool has a shebang.

    Where I work 100% of (hundreds of) shell scripts shipped to customers
    do not have a #! line. That's because they are required to conform to
    POSIX, and POSIX says that if the first line starts with #! the results
    are unspecified.

    --
    Geoff Clare <[email protected]>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From John McCue@21:1/5 to Geoff Clare on Fri Aug 5 18:51:53 2022
    Geoff Clare <[email protected]d> wrote:
    <snip>

    Where I work 100% of (hundreds of) shell scripts shipped to customers
    do not have a #! line. That's because they are required to conform to
    POSIX, and POSIX says that if the first line starts with #! the results
    are unspecified.

    I never read POSIX, but '#!' statement is very odd. I do
    not doubt POSIX says that since I think it was first done
    many decades ago by a US Gov committee.

    That statement would make my head spin, as you know, a '#'
    is a comment in all the shells I am aware of.
    The phrase "good enough for Gov Work" comes to mind :)

    --
    [t]csh(1) - "An elegant shell, for a more... civilized age."
    - Paraphrasing Star Wars

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lew Pitcher@21:1/5 to Keith Thompson on Fri Aug 5 19:50:57 2022
    On Fri, 05 Aug 2022 12:32:01 -0700, Keith Thompson wrote:

    John McCue <[email protected]> writes:
    Geoff Clare <[email protected]d> wrote:
    <snip>

    Where I work 100% of (hundreds of) shell scripts shipped to customers
    do not have a #! line. That's because they are required to conform to
    POSIX, and POSIX says that if the first line starts with #! the results
    are unspecified.

    I never read POSIX, but '#!' statement is very odd. I do
    not doubt POSIX says that since I think it was first done
    many decades ago by a US Gov committee.

    IEEE, not the US Government.

    That statement would make my head spin, as you know, a '#'
    is a comment in all the shells I am aware of.
    The phrase "good enough for Gov Work" comes to mind :)

    Yes, # introduces a comment in most shells.

    I haven't found that statement in POSIX about #!, but I presume the
    reason is that saying it's unspecified allows the usual implementation
    while not requiring POSIX to specify the behavior.

    I'd assume this as well.

    The Open Group Base Specifications Issue 7, 2018 edition
    IEEE Std 1003.1-2017 (Revision of IEEE Std 1003.1-2008)

    Chapter 2 Shell Command Language
    2.1 Shell Introduction

    "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."

    If POSIX said nothing about #! then it would imply that it has to be
    treated as an ordinary comment.

    Since the #! feature is nearly universal for Unix-like systems and
    predates POSIX, I'm not sure why POSIX didn't standardize it.

    I imagine that, because the #! names an interpreter, and that interpreter
    isn't part of the Shell specifications, the POSIX Shell documentation can't make any guarantees or assumptions about how that (unspecified) interpreter might affect the execution of the standardized shell code. For instance,
    if the #! names the Whitespace programming language interpreter
    (see https://en.wikipedia.org/wiki/Whitespace_(programming_language) ) as
    it's interpreter, the shell code still represents a valid program, but
    will not generate the results expected from a POSIX Shell program.


    --
    Lew Pitcher
    "In Skills, We Trust"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Keith Thompson@21:1/5 to John McCue on Fri Aug 5 12:32:01 2022
    John McCue <[email protected]> writes:
    Geoff Clare <[email protected]d> wrote:
    <snip>

    Where I work 100% of (hundreds of) shell scripts shipped to customers
    do not have a #! line. That's because they are required to conform to
    POSIX, and POSIX says that if the first line starts with #! the results
    are unspecified.

    I never read POSIX, but '#!' statement is very odd. I do
    not doubt POSIX says that since I think it was first done
    many decades ago by a US Gov committee.

    IEEE, not the US Government.

    That statement would make my head spin, as you know, a '#'
    is a comment in all the shells I am aware of.
    The phrase "good enough for Gov Work" comes to mind :)

    Yes, # introduces a comment in most shells.

    I haven't found that statement in POSIX about #!, but I presume the
    reason is that saying it's unspecified allows the usual implementation
    while not requiring POSIX to specify the behavior.

    If POSIX said nothing about #! then it would imply that it has to be
    treated as an ordinary comment.

    Since the #! feature is nearly universal for Unix-like systems and
    predates POSIX, I'm not sure why POSIX didn't standardize it.

    --
    Keith Thompson (The_Other_Keith) [email protected]
    Working, but not speaking, for Philips
    void Void(void) { Void(); } /* The recursive call of the void */

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Eli the Bearded@21:1/5 to [email protected] on Fri Aug 5 20:18:57 2022
    In comp.unix.shell, Lew Pitcher <[email protected]> wrote:
    On Fri, 05 Aug 2022 12:32:01 -0700, Keith Thompson wrote:
    Yes, # introduces a comment in most shells.

    And indeed, #! is a comment _to the shell_. It's not a comment to the
    kernel running exec(), there it specifies what intrepreter to use. (ELF
    and a.out are other interpreters that have different file identification methods.)

    I haven't found that statement in POSIX about #!, but I presume the
    reason is that saying it's unspecified allows the usual implementation
    while not requiring POSIX to specify the behavior.

    I'd assume this as well.

    Some unix systems have required a space, eg '#! /bin/sh' and some
    require no space, so right away I can imagine POSIX has trouble. Then there's the
    issue of arguments on the #! line.

    Tools like Perl might examine the #! line and do intelligent things with
    it. Or may see ^# and just treat it as another comment.

    $ cat > /tmp/eg
    #!/bin/ksh
    ps -lp $$
    ^D
    $ perl /tmp/eg
    UID PID PPID CPU PRI NI VSZ RSS WCHAN STAT TTY TIME COMMAND
    13785 7025 2460 0 85 0 18036 1836 pause S+ pts/34 0:00.01 /bin/ksh
    $

    Elijah
    ------
    #!/bin/env is another fun quirk

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Keith Thompson@21:1/5 to Eli the Bearded on Fri Aug 5 13:54:08 2022
    Eli the Bearded <*@eli.users.panix.com> writes:
    In comp.unix.shell, Lew Pitcher <[email protected]> wrote:
    On Fri, 05 Aug 2022 12:32:01 -0700, Keith Thompson wrote:
    Yes, # introduces a comment in most shells.

    And indeed, #! is a comment _to the shell_. It's not a comment to the
    kernel running exec(), there it specifies what intrepreter to use. (ELF
    and a.out are other interpreters that have different file identification methods.)

    I haven't found that statement in POSIX about #!, but I presume the
    reason is that saying it's unspecified allows the usual implementation
    while not requiring POSIX to specify the behavior.

    I'd assume this as well.

    Some unix systems have required a space, eg '#! /bin/sh' and some
    require no space, so right away I can imagine POSIX has trouble. Then there's the
    issue of arguments on the #! line.

    I've never heard of a system that requires a space after the "#!", and I
    don't *think* I've heard of a system that forbids it. As far as I know,
    it's always been optional.

    Arguments after the command name are certainly an issue. But POSIX
    *could* have documented #! and left some aspects of it unspecified. (If
    it did so, it wouldn't be in the "Shell Command Language" section but
    under system(), popen(), and/or exec*(), since a script with a #! isn't necessarily a shell script.)

    There are some non-normative references to #! in POSIX. For example,
    the section on environ, execl, et al says:

    Another way that some historical implementations handle shell
    scripts is by recognizing the first two bytes of the file as the
    character string "#!" and using the remainder of the first line of
    the file as the name of the command interpreter to execute.

    Tools like Perl might examine the #! line and do intelligent things with
    it. Or may see ^# and just treat it as another comment.

    $ cat > /tmp/eg
    #!/bin/ksh
    ps -lp $$
    ^D
    $ perl /tmp/eg
    UID PID PPID CPU PRI NI VSZ RSS WCHAN STAT TTY TIME COMMAND
    13785 7025 2460 0 85 0 18036 1836 pause S+ pts/34 0:00.01 /bin/ksh
    $

    Elijah
    ------
    #!/bin/env is another fun quirk

    /bin/env doesn't exist on my system (Ubuntu); it's /usr/bin/env.

    --
    Keith Thompson (The_Other_Keith) [email protected]
    Working, but not speaking, for Philips
    void Void(void) { Void(); } /* The recursive call of the void */

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Geoff Clare on Sat Aug 6 11:32:56 2022
    On 05.08.2022 15:07, Geoff Clare wrote:
    Ed Morton wrote:

    On 8/4/2022 4:06 PM, Dan Espen wrote:
    [email protected] writes:

    On Thu, 04 Aug 2022 20:28:06 GMT
    [email protected] (Scott Lurndal) wrote:
    [email protected] writes:
    Should. How often do you see it in practice?


    100%. As noted in other posts, we use a number of different interactive >>>>> shells, and a number of scripting languages (tcsh, ksh, bash, perl, python,
    tcl, et alia). And that's been true for every POE I've worked in for >>>>> the last three plus decades (system or processor OEMs primarily).

    Don't believe you. I've seen more scripts than I can count that didn't >>>> have the hash bang at the start. No idea what a she-bang is. Sounds like >>>> a service for sailors in a port.

    Well, where I worked, every shell script we shipped to customers had
    a hash bang. Feel free to not believe me too.


    Likewise, 100% of the shell scripts shipped to customers or used as a
    tool has a shebang.

    Where I work 100% of (hundreds of) shell scripts shipped to customers
    do not have a #! line. That's because they are required to conform to
    POSIX, and POSIX says that if the first line starts with #! the results
    are unspecified.

    In the past we rarely shipped _scripts_ to customers, rather mostly
    large program systems or single binaries or complete runtime packages.
    Anyway, an executable script has to be started with the appropriate
    (well defined) interpreter, so an explicit shebang definition would
    be the cleanest way, IMO. (Personally and privately I explicitly use
    the interpreter on the script file in most cases.) But what we (or
    our company) ships is beyond a generally valid statement. If I inspect
    the PATH on my Linux system and the script files located there I find
    round about 1000 scripts, all with a #! line and with the interpreters
    depicted in the list

    324 #!/bin/sh
    152 #!/usr/bin/perl
    132 #!/usr/bin/perl -w
    92 #!/usr/bin/python
    72 #! /bin/sh
    56 #!/bin/bash
    37 #! /usr/bin/perl
    31 #!/bin/sh -e
    24 #! /usr/bin/python
    15 #! /usr/bin/env
    13 #!/usr/bin/env python
    11 #! /bin/bash
    6 #!/bin/sh -
    5 #!/usr/bin/ruby1.8
    3 #!/bin/bash -e
    3 #! /usr/bin/python2.7
    2 #!/usr/bin/wish
    2 #!/usr/bin/env ruby
    1 #!/usr/bin/python2.7
    1 #!/usr/bin/python -Es
    1 #!/usr/bin/perl -wl
    1 #!/usr/bin/perl --
    1 #!/usr/bin/guile -s
    1 #!/usr/bin/env perl
    1 #!/usr/bin/env nickle
    1 #!/usr/bin/env bash
    1 #!/bin/sh -f
    1 #!/bin/sh -eu
    1 #!/bin/mksh
    1 #! /usr/bin/python3


    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Keith Thompson on Sat Aug 6 16:44:01 2022
    On 2022-08-05, Keith Thompson <[email protected]> wrote:
    John McCue <[email protected]> writes:
    Geoff Clare <[email protected]d> wrote:
    <snip>

    Where I work 100% of (hundreds of) shell scripts shipped to customers
    do not have a #! line. That's because they are required to conform to
    POSIX, and POSIX says that if the first line starts with #! the results
    are unspecified.

    I never read POSIX, but '#!' statement is very odd. I do
    not doubt POSIX says that since I think it was first done
    many decades ago by a US Gov committee.

    IEEE, not the US Government.

    That statement would make my head spin, as you know, a '#'
    is a comment in all the shells I am aware of.
    The phrase "good enough for Gov Work" comes to mind :)

    Yes, # introduces a comment in most shells.

    I haven't found that statement in POSIX about #!, but I presume the
    reason is that saying it's unspecified allows the usual implementation
    while not requiring POSIX to specify the behavior.

    The usual implementation processes #! like a comment, since the
    hash bang mechanism is designed to be invisible to an interpreter
    which uses # comments, imposing no requirements on it.

    Therefore, the only good reason the spec would be bringing in
    unspecified behavior in the treatment of a certain shape of comment in a certain place in the file would be to allow UNusual implementations of
    hash bang, where the interpreter has some responsibility in parsing the
    hash bang line and possibly deferring to a different interpreter.

    One reason why an interpreter would look at the hash bang line specially
    would be to parse multiple command line arguments out of it in an implementation where only one argument is allowed.

    #!/path/to/interp --multiple --args --here

    Here interp, before processing any other arguments, could open the
    script, see the #! and then edit its argument list from that
    information.

    The POSIX wording has the effect of allowing the above tricks.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Geoff Clare@21:1/5 to Keith Thompson on Mon Aug 8 13:48:10 2022
    Keith Thompson wrote:

    Since the #! feature is nearly universal for Unix-like systems and
    predates POSIX, I'm not sure why POSIX didn't standardize it.

    I think it is mainly because POSIX doesn't specify pathnames for
    utilities. It is very common to start a shell script with #! /bin/sh
    but on Solaris 10 and earlier that would get you an old Bourne shell,
    not a POSIX conforming shell (which would need #! /usr/xpg4/bin/sh).

    So even if POSIX specified #!, portable applications wouldn't be
    able to hard-code that line. They would need a config/install process
    that finds the right version of sh (or whatever utility) and adds or
    updates the #! line.

    --
    Geoff Clare <[email protected]>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Keith Thompson@21:1/5 to Geoff Clare on Mon Aug 8 10:58:58 2022
    Geoff Clare <[email protected]d> writes:
    Keith Thompson wrote:
    Since the #! feature is nearly universal for Unix-like systems and
    predates POSIX, I'm not sure why POSIX didn't standardize it.

    I think it is mainly because POSIX doesn't specify pathnames for
    utilities. It is very common to start a shell script with #! /bin/sh
    but on Solaris 10 and earlier that would get you an old Bourne shell,
    not a POSIX conforming shell (which would need #! /usr/xpg4/bin/sh).

    So even if POSIX specified #!, portable applications wouldn't be
    able to hard-code that line. They would need a config/install process
    that finds the right version of sh (or whatever utility) and adds or
    updates the #! line.

    Sure, but POSIX could have specified the behavior of #! and the meaning
    of its argument(s) without depending on any particular pathnames.

    --
    Keith Thompson (The_Other_Keith) [email protected]
    Working, but not speaking, for Philips
    void Void(void) { Void(); } /* The recursive call of the void */

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)