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 <u...@stderr.spb.ru> > Message-ID: <zvex2vpndqb8a...@snips.stderr.spb.ru> > > | 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