tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: interactive shell detection in shrc



At Sat, 28 Sep 2024 05:35:02 +0700, Robert Elz <kre%munnari.OZ.AU@localhost> 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 <gwoods%acm.org@localhost>

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

Attachment: pgpFmtiOKYmMC.pgp
Description: OpenPGP Digital Signature



Home | Main Index | Thread Index | Old Index