[TUHS] Shell Level...

Kurt H Maier khm at sciops.net
Mon Jan 20 18:39:28 AEST 2020


On Mon, Jan 20, 2020 at 09:15:56AM +0100, markus schnalke wrote:
> Hoi.
> 
> [2020-01-19 14:22] Grant Taylor via TUHS <tuhs at minnie.tuhs.org>
> >
> > Have you ever used shell level, $SHLVL, in your weekly ~> daily use of Unix?
> 
> What's the use of it? 

I have seen it used -- and I do not use it this way myself -- to
construct a sort of work batch, where a control script launches many
instances of itself, which then inspect $SHLVL to determine that they
are subordinates, and process elements of a central work queue.  The
parent instance would monitor the number of copies of the script in use
and launch new subordinates in the case some of them exited for whatever
reason.

The whole thing felt alien, but it seemed to work.  

The other, more common use I've seen is to e.g. clear the terminal
window on logout (e.g. in .bash_logout when SHLVL=1) but not when
exiting any nested shell.

It's not POSIX, so I've never relied on it.

khm


More information about the TUHS mailing list