tech-userlevel archive

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

Re: interactive shell detection in shrc



    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.

It makes no difference when used via "." (which is how the startup
files are typically read) which are kind of like functions (without
parameters, and so "return" is valid) - but the return won't work
if used as a script, you'd need to use exit instead ... and exit is
something that you absolutely wouldn't want to do when the file is
being used normally.

kre



Home | Main Index | Thread Index | Old Index