Re: interactive shell detection in shrc
"Greg A. Woods" <[email protected]>
| Newsgroups | gmane.os.netbsd.devel.userlevel |
|---|---|
| Organization | Planix, Inc. |
| Message-ID | <[email protected]> |
At Sat, 28 Sep 2024 05:35:02 +0700, Robert Elz <[email protected]> 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 <[email protected]> Kelowna, BC +1 250 762-7675 RoboHack <[email protected]> Planix, Inc. <[email protected]> Avoncote Farms <[email protected]>
signature.asc
(application/pgp-signature, 195 B)
-----BEGIN PGP SIGNATURE----- iF0EABECAB0WIQRuK6dmwVAucmRxuh9mfXG3eL/0fwUCZvhC7QAKCRBmfXG3eL/0 f3SGAKDZAj0uoptNfXypGd4KikB9CkfmVACg9iBTKzgbxbIIjAYiwK/F2w6IkGw= =xm0X -----END PGP SIGNATURE-----