tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: interactive shell detection in shrc
On Tue, Sep 24, 2024 at 00:06:22 +0700, Robert Elz wrote:
> Date: Mon, 23 Sep 2024 12:16:10 +0300
> From: Valery Ushakov <uwe%stderr.spb.ru@localhost>
> Message-ID: <ZvEx2vPnDQB8A7vJ%snips.stderr.spb.ru@localhost>
>
> | I'd like to switch this to the "early return" style, something like
> |
> | # the rest of the file is for interactive shells only
> | case "$-" in *i*) ;; *) return ;; esac
>
> I think the primary motivation for not doing it that way is so
> the file can be used as a script ("sh .shrc") for testing.
That's kinda moot. shrc is there to affect the state of a shell in a
way that is visible in subsequent use of that same shell. sh .shrc
allows you to check that .shrc has no failures, but you cannot test
how it affected the shell (as opposed to sourcing it). So if the
purpose of the sh .shrc excercise is just to check that .shrc can be
processed without failure one may almost unironically argue that the
return approach is actually better, b/c it will check the
interactive-only part too: sh .shrc is a _non_ interactive shell and
return in the non-interacive branch is ingored, so shell falls through
to the interactive-only part.
I would say win-win :)
-uwe
Home |
Main Index |
Thread Index |
Old Index