At Fri, 27 Sep 2024 07:14:46 +0700, Robert Elz <k...@munnari.oz.au> wrote:
Subject: Re: interactive shell detection in shrc
>
>     Date:        Thu, 26 Sep 2024 15:16:39 -0700
>     From:        "Greg A. Woods" <wo...@planix.ca>
>     Message-ID:  <m1stwmt-0036s2C@more.local>
>
>   | I'm very curious:  why did you include "m" in that test?
>
> I wondered about that as well.   But I suspect you have
> supplied the answer.
>
>   | I do note the following from the bosh(1) manual:
>   |
>   |   ... POSIX requires that job control is auto-enabled for
>   |   interactive shells ...
>
> It actually requires it to be on by default in interactive shells,
> that's almost what the above says, but it could be read as not
> allowing "sh +m" to start an interactive shell with job control
> disabled -- which is not what posix requires.
>
>   | But I'm pretty sure the key word there is "interactive", which will by
>   | definition also mean they have 'i' in $-.
>
> It would, but as you point out -i isn't always available there, but -m
> should be,

But that was my point!  "m" is not in $- either!

However it seems my own test conflates the condition of being a "login
shell" with being "interactive".

Reading POSIX Issue 7 sh(1) just now I note the following text:

        If the -i option is present, or if there are no operands and the
        shell's standard input and standard error are attached to a
        terminal, the shell is considered to be interactive.

So there's nothing in POSIX about login(1) tacking a leading hyphen on
and using that to trigger the shell to become a login shell.

Indeed from what I can tell POSIX has nothing whatsoever to say about
"login shells" nor /etc/profile or $HOME/.profile.

I guess to be entirely POSIX compatible my test should include:

        tty >/dev/null 2>&1 && tty <&1 >/dev/null 2>&1 &&
                [ "$0" = "$SHELL" ] &&
                _interactive=true

--
                                        Greg A. Woods <gwo...@acm.org>

Kelowna, BC     +1 250 762-7675           RoboHack <wo...@robohack.ca>
Planix, Inc. <wo...@planix.com>     Avoncote Farms <wo...@avoncote.ca>

Attachment: pgpKs5V8BaRYw.pgp
Description: OpenPGP Digital Signature

Reply via email to