At Sat, 28 Sep 2024 05:35:02 +0700, Robert Elz <k...@munnari.oz.au> wrote:
Subject: Re: interactive shell detection in shrc
>
> But any current POSIX compat sh should have 'i' in $- if it is interactive.
> That is required.

Ah, but only since Issue 8.

That does clarify things, but it's rather late in the game, and it does
rather explicitly change the meaning of "$-", if somewhat subtly.


>   | I guess to be entirely POSIX compatible my test should include:
>   |
>   |   tty >/dev/null 2>&1 && tty <&1 >/dev/null 2>&1 &&
>
> The second of those would need to be testing (the pre-redirected)
> stderr, not stdout, interactive shells don't care where stdout has
> been sent (though the user probably does).

Oy!  Indeed I meant "<&2".  I was seeing the other "2>&1" and thinking I
had it.

> But as Steffen (kind of) indicated, "test -t 0 && test -t 2" is
> probably an easier way than using tty.

Well, I'll be.  I don't remember ever using "test -t"!  I think I must
have skipped over it entirely all these years!  So I now have:

        if [ -t 0 -a -t 2 -a "$0" = "$SHELL" ]; then
                _interactive=true
        fi

--
                                        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: pgp59aS8hdNwT.pgp
Description: OpenPGP Digital Signature

Reply via email to