The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
* [TUHS] Shell Level...
@ 2020-01-19 21:22 Grant Taylor via TUHS
  2020-01-19 23:21 ` Thomas Paulsen
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Grant Taylor via TUHS @ 2020-01-19 21:22 UTC (permalink / raw)
  To: The Unix Heritage Society

[-- Attachment #1: Type: text/plain, Size: 959 bytes --]

Hi,

Have you ever used shell level, $SHLVL, in your weekly ~> daily use of Unix?

I had largely dismissed it until a recent conversation in a newsgroup. 
I learned that shelling out of programs also increments the shell level. 
  I.e. :shell or :!/bin/sh in vim.

Someone also mentioned quickly starting a new sub-shell from the current 
shell for quick transient tasks, i.e. dc / bc, mount / cp / unmount, 
{,r,s}cp, etc., in an existing terminal window to avoid cluttering that 
first terminals history with the transient commands.

That got me to wondering if there were other uses for shell level 
($SHLVL).  Hence my question.

This is more about using (contemporary) shells on Unix, than it is about 
Unix history.  But I suspect that TUHS is one of the best places to find 
the most people that are likely to know about shell level.  Feel free to 
reply to COFF if it would be better there.



-- 
Grant. . . .
unix || die


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4013 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [TUHS] Shell Level...
  2020-01-19 21:22 [TUHS] Shell Level Grant Taylor via TUHS
@ 2020-01-19 23:21 ` Thomas Paulsen
  2020-01-20  8:15 ` markus schnalke
  2020-01-20 23:43 ` Greg A. Woods
  2 siblings, 0 replies; 13+ messages in thread
From: Thomas Paulsen @ 2020-01-19 23:21 UTC (permalink / raw)
  To: Grant Taylor; +Cc: tuhs

>Have you ever used shell level, $SHLVL, in your weekly ~> daily use of Unix?
Its part of my default $PS1 since > 30 years when I anticipated' it under SysV4/ksh because of my frequent use of sub-shells then. Luckily its a bash build-in . Thanks RMS/Chet.



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [TUHS] Shell Level...
  2020-01-19 21:22 [TUHS] Shell Level Grant Taylor via TUHS
  2020-01-19 23:21 ` Thomas Paulsen
@ 2020-01-20  8:15 ` markus schnalke
  2020-01-20  8:39   ` Kurt H Maier
                     ` (2 more replies)
  2020-01-20 23:43 ` Greg A. Woods
  2 siblings, 3 replies; 13+ messages in thread
From: markus schnalke @ 2020-01-20  8:15 UTC (permalink / raw)
  To: tuhs

Hoi.

[2020-01-19 14:22] Grant Taylor via TUHS <tuhs@minnie.tuhs.org>
>
> Have you ever used shell level, $SHLVL, in your weekly ~> daily use of Unix?

What's the use of it? The only use of $SHLVL I can think of is the
answer to the question if ^D will close the last shell or just a
sub shell. I hardly ever ask myself this question. Probably that
starts to become relevant when you open sub shells frequently.


> Someone also mentioned quickly starting a new sub-shell from the current 
> shell for quick transient tasks, i.e. dc / bc, mount / cp / unmount, 
> {,r,s}cp, etc., in an existing terminal window to avoid cluttering that 
> first terminals history with the transient commands.

With tmux or screen at hand, this use case is obsolete for me.
(Besides, my shell doesn't know about $SHLVL.)

This all pretty much depends on your working habits, of course.
For instance, I never use history expansion but search the
history frequently, thus additional entries in the shell history
are no problem. I rather like to have all shell histories merged
into one for having search access to all the commands I executed.
This seems to be more of a modern shell usage concept.

Job control, OTOH, I use a lot, to suspend the editor, grep for
something, resume the editor, and the like. Which seems to be more
of an older style usage concept.


> That got me to wondering if there were other uses for shell level 
> ($SHLVL).  Hence my question.

I'm interested as well, as I've got difficulties imagine these
uses.


One thing to clarify: Are you looking for uses of the shell
variable $SHLVL or for uses of frequent sub shells?


meillo

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [TUHS] Shell Level...
  2020-01-20  8:15 ` markus schnalke
@ 2020-01-20  8:39   ` Kurt H Maier
  2020-01-21 20:42     ` Grant Taylor via TUHS
  2020-01-20 19:40   ` Theodore Y. Ts'o
  2020-01-20 23:55   ` Greg A. Woods
  2 siblings, 1 reply; 13+ messages in thread
From: Kurt H Maier @ 2020-01-20  8:39 UTC (permalink / raw)
  To: markus schnalke; +Cc: tuhs

On Mon, Jan 20, 2020 at 09:15:56AM +0100, markus schnalke wrote:
> Hoi.
> 
> [2020-01-19 14:22] Grant Taylor via TUHS <tuhs@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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [TUHS] Shell Level...
  2020-01-20  8:15 ` markus schnalke
  2020-01-20  8:39   ` Kurt H Maier
@ 2020-01-20 19:40   ` Theodore Y. Ts'o
  2020-01-20 23:51     ` Terry Jones
  2020-01-21 20:44     ` Grant Taylor via TUHS
  2020-01-20 23:55   ` Greg A. Woods
  2 siblings, 2 replies; 13+ messages in thread
From: Theodore Y. Ts'o @ 2020-01-20 19:40 UTC (permalink / raw)
  To: markus schnalke; +Cc: tuhs

On Mon, Jan 20, 2020 at 09:15:56AM +0100, markus schnalke wrote:
> Hoi.
> 
> [2020-01-19 14:22] Grant Taylor via TUHS <tuhs@minnie.tuhs.org>
> >
> > Have you ever used shell level, $SHLVL, in your weekly ~> daily use of Unix?
> 
> What's the use of it? The only use of $SHLVL I can think of is the
> answer to the question if ^D will close the last shell or just a
> sub shell. I hardly ever ask myself this question. Probably that
> starts to become relevant when you open sub shells frequently.

<Raises hand>

The normal reason why I'm starting subshells is because I need to
control various environment variables on an ad-hoc basis.  It might be
PYTHONPATH, KRB5CCNAME, GPG_AGENT_INFO, LD_LIBRARY_PATH, or some
combination of the above.  Back when I was regularly using Kerberos
root/admin bits, I had some hard-coded shell aliases to indicate
explicitly I was in a shell that was using my
tytso/root@ATHENA.MIT.EDU or tytso/admin@ATHENA.MIT.EDU kerberos
tickets.

But for ad-hoc use cases, SHLVL is great way to track whether I'm a
non-standard shell environment.  For me, some use case probably comes
up at least week or two.

> With tmux or screen at hand, this use case is obsolete for me.
> (Besides, my shell doesn't know about $SHLVL.)

Before I was using bash regularly, I had hard-coded something like
SHLVL in my .tcshrc.

						- Ted

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [TUHS] Shell Level...
  2020-01-19 21:22 [TUHS] Shell Level Grant Taylor via TUHS
  2020-01-19 23:21 ` Thomas Paulsen
  2020-01-20  8:15 ` markus schnalke
@ 2020-01-20 23:43 ` Greg A. Woods
  2 siblings, 0 replies; 13+ messages in thread
From: Greg A. Woods @ 2020-01-20 23:43 UTC (permalink / raw)
  To: The Unix Heritage Society mailing list

[-- Attachment #1: Type: text/plain, Size: 1105 bytes --]

At Sun, 19 Jan 2020 14:22:29 -0700, Grant Taylor via TUHS <tuhs@minnie.tuhs.org> wrote:
Subject: [TUHS] Shell Level...
>
> Have you ever used shell level, $SHLVL, in your weekly ~> daily use of Unix?

I invented my own variant, $LEV, for Ksh, starting before 1993, probably
when I first started using DMD-5620 terminals and layers, though
possibly slightly before that when I first started using Ksh (about 1989
when I bought a used ATT3B2/400 for home use).  I used my own $LEV in my
prompt (or the window title, if using a windowing system) just to remind
me if I'd started a sub-shell for some reason, such as in order to
preserve my current working directory and environment.

Early Ksh didn't have $SHLVL, and it's not universal (i.e. POSIX), so
I've never really used $SHLVL itself (though I have very recently added
a hook to set my $LEV from it IFF it is available).

See https://github.com/robohack/dotfiles  :-)

--
					Greg A. Woods <gwoods@acm.org>

Kelowna, BC     +1 250 762-7675           RoboHack <woods@robohack.ca>
Planix, Inc. <woods@planix.com>     Avoncote Farms <woods@avoncote.ca>

[-- Attachment #2: OpenPGP Digital Signature --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [TUHS] Shell Level...
  2020-01-20 19:40   ` Theodore Y. Ts'o
@ 2020-01-20 23:51     ` Terry Jones
  2020-01-21 20:44     ` Grant Taylor via TUHS
  1 sibling, 0 replies; 13+ messages in thread
From: Terry Jones @ 2020-01-20 23:51 UTC (permalink / raw)
  To: Theodore Y. Ts'o; +Cc: tuhs

[-- Attachment #1: Type: text/plain, Size: 1882 bytes --]

I also make new shells fairly regularly, about half the time because I wan
to set some variables that I don't want to have to reset.  Then if/when I
forget which window I was in, I can check with SHLVL (at least when using
bash, which I normally don't do).  But I'm normally in & out of the
sub-shells very quickly so don't often need to check.

Terry


On Mon, Jan 20, 2020 at 8:43 PM Theodore Y. Ts'o <tytso@mit.edu> wrote:

> On Mon, Jan 20, 2020 at 09:15:56AM +0100, markus schnalke wrote:
> > Hoi.
> >
> > [2020-01-19 14:22] Grant Taylor via TUHS <tuhs@minnie.tuhs.org>
> > >
> > > Have you ever used shell level, $SHLVL, in your weekly ~> daily use of
> Unix?
> >
> > What's the use of it? The only use of $SHLVL I can think of is the
> > answer to the question if ^D will close the last shell or just a
> > sub shell. I hardly ever ask myself this question. Probably that
> > starts to become relevant when you open sub shells frequently.
>
> <Raises hand>
>
> The normal reason why I'm starting subshells is because I need to
> control various environment variables on an ad-hoc basis.  It might be
> PYTHONPATH, KRB5CCNAME, GPG_AGENT_INFO, LD_LIBRARY_PATH, or some
> combination of the above.  Back when I was regularly using Kerberos
> root/admin bits, I had some hard-coded shell aliases to indicate
> explicitly I was in a shell that was using my
> tytso/root@ATHENA.MIT.EDU or tytso/admin@ATHENA.MIT.EDU kerberos
> tickets.
>
> But for ad-hoc use cases, SHLVL is great way to track whether I'm a
> non-standard shell environment.  For me, some use case probably comes
> up at least week or two.
>
> > With tmux or screen at hand, this use case is obsolete for me.
> > (Besides, my shell doesn't know about $SHLVL.)
>
> Before I was using bash regularly, I had hard-coded something like
> SHLVL in my .tcshrc.
>
>                                                 - Ted
>

[-- Attachment #2: Type: text/html, Size: 2613 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [TUHS] Shell Level...
  2020-01-20  8:15 ` markus schnalke
  2020-01-20  8:39   ` Kurt H Maier
  2020-01-20 19:40   ` Theodore Y. Ts'o
@ 2020-01-20 23:55   ` Greg A. Woods
  2020-01-21 20:46     ` Grant Taylor via TUHS
  2 siblings, 1 reply; 13+ messages in thread
From: Greg A. Woods @ 2020-01-20 23:55 UTC (permalink / raw)
  To: The Unix Heritage Society mailing list

[-- Attachment #1: Type: text/plain, Size: 733 bytes --]

At Mon, 20 Jan 2020 09:15:56 +0100, markus schnalke <meillo@marmaro.de> wrote:
Subject: Re: [TUHS] Shell Level...
>
> What's the use of it? The only use of $SHLVL I can think of is the
> answer to the question if ^D will close the last shell or just a
> sub shell. I hardly ever ask myself this question. Probably that
> starts to become relevant when you open sub shells frequently.

I've always just used "set ignoreeof" (first in Csh and later in Ksh),
but just in my initial login shell (i.e. set in ~/.login), to prevent ^D
from logging me out.

--
					Greg A. Woods <gwoods@acm.org>

Kelowna, BC     +1 250 762-7675           RoboHack <woods@robohack.ca>
Planix, Inc. <woods@planix.com>     Avoncote Farms <woods@avoncote.ca>

[-- Attachment #2: OpenPGP Digital Signature --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [TUHS] Shell Level...
  2020-01-20  8:39   ` Kurt H Maier
@ 2020-01-21 20:42     ` Grant Taylor via TUHS
  0 siblings, 0 replies; 13+ messages in thread
From: Grant Taylor via TUHS @ 2020-01-21 20:42 UTC (permalink / raw)
  To: tuhs

[-- Attachment #1: Type: text/plain, Size: 307 bytes --]

On 1/20/20 1:39 AM, Kurt H Maier wrote:
> 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.

Interesting use case.

Thank you for sharing Kurt.



-- 
Grant. . . .
unix || die


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4013 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [TUHS] Shell Level...
  2020-01-20 19:40   ` Theodore Y. Ts'o
  2020-01-20 23:51     ` Terry Jones
@ 2020-01-21 20:44     ` Grant Taylor via TUHS
  2020-01-21 23:10       ` Theodore Y. Ts'o
  1 sibling, 1 reply; 13+ messages in thread
From: Grant Taylor via TUHS @ 2020-01-21 20:44 UTC (permalink / raw)
  To: tuhs

[-- Attachment #1: Type: text/plain, Size: 730 bytes --]

On 1/20/20 12:40 PM, Theodore Y. Ts'o wrote:
> The normal reason why I'm starting subshells is because I need to control 
> various environment variables on an ad-hoc basis.  It might be PYTHONPATH, 
> KRB5CCNAME, GPG_AGENT_INFO, LD_LIBRARY_PATH, or some combination of 
> the above.  Back when I was regularly using Kerberos root/admin bits, I 
> had some hard-coded shell aliases to indicate explicitly I was in a shell 
> that was using my tytso/root@ATHENA.MIT.EDU or tytso/admin@ATHENA.MIT.EDU 
> kerberos tickets.

If I'm understanding you correctly, you used a sub-shell with a modified 
/ task / process specific environment.  Correct?

Thank you for sharing Theodore.



-- 
Grant. . . .
unix || die


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4013 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [TUHS] Shell Level...
  2020-01-20 23:55   ` Greg A. Woods
@ 2020-01-21 20:46     ` Grant Taylor via TUHS
  2020-01-21 23:39       ` Greg A. Woods
  0 siblings, 1 reply; 13+ messages in thread
From: Grant Taylor via TUHS @ 2020-01-21 20:46 UTC (permalink / raw)
  To: tuhs

[-- Attachment #1: Type: text/plain, Size: 488 bytes --]

On 1/20/20 4:55 PM, Greg A. Woods wrote:
> I've always just used "set ignoreeof" (first in Csh and later in Ksh), 
> but just in my initial login shell (i.e. set in ~/.login), to prevent 
> ^D from logging me out.

It sounds like you're making your initial / login shell behave 
differently based on the shell level.

Conceptually similar to Kurt's example, just changing a different aspect 
of your shell.

Thank you for sharing Greg.



-- 
Grant. . . .
unix || die


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4013 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [TUHS] Shell Level...
  2020-01-21 20:44     ` Grant Taylor via TUHS
@ 2020-01-21 23:10       ` Theodore Y. Ts'o
  0 siblings, 0 replies; 13+ messages in thread
From: Theodore Y. Ts'o @ 2020-01-21 23:10 UTC (permalink / raw)
  To: Grant Taylor; +Cc: tuhs

On Tue, Jan 21, 2020 at 01:44:07PM -0700, Grant Taylor via TUHS wrote:
> On 1/20/20 12:40 PM, Theodore Y. Ts'o wrote:
> > The normal reason why I'm starting subshells is because I need to
> > control various environment variables on an ad-hoc basis.  It might be
> > PYTHONPATH, KRB5CCNAME, GPG_AGENT_INFO, LD_LIBRARY_PATH, or some
> > combination of the above.  Back when I was regularly using Kerberos
> > root/admin bits, I had some hard-coded shell aliases to indicate
> > explicitly I was in a shell that was using my tytso/root@ATHENA.MIT.EDU
> > or tytso/admin@ATHENA.MIT.EDU kerberos tickets.
> 
> If I'm understanding you correctly, you used a sub-shell with a modified /
> task / process specific environment.  Correct?

Correct.  And I would often suspend the shell when I didn't need to
use the Kerberos administration credentials, and then go back to it
later when I did need it, and since I was often bouncing back and
forth between the sub-shell and the parent shell, having the SHLVL
displayed in the prompt for non-top-level shells was useful.

For similar reasons, my shell prompt will also display what git branch
I happen to be one.  For example:

<tytso@lambda> {/usr/projects/e2fsprogs/e2fsprogs-maint}, level 2   (debian/master)
1001% 

Says that I'm on the debian/master git branch, and "level 2" indicates
that I'm in a subshell.  (If I'm in a top level shell, no level will
be printed at all.)  The prompt also displays the hostname ("lambda"
in this case") which is super-useful to identify remote logins.

	     	 	    		  	     - Ted

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [TUHS] Shell Level...
  2020-01-21 20:46     ` Grant Taylor via TUHS
@ 2020-01-21 23:39       ` Greg A. Woods
  0 siblings, 0 replies; 13+ messages in thread
From: Greg A. Woods @ 2020-01-21 23:39 UTC (permalink / raw)
  To: The Unix Heritage Society mailing list

[-- Attachment #1: Type: text/plain, Size: 1322 bytes --]

At Tue, 21 Jan 2020 13:46:14 -0700, Grant Taylor via TUHS <tuhs@minnie.tuhs.org> wrote:
Subject: Re: [TUHS] Shell Level...
>
> [1  <text/plain (en-US); windows-1252 (quoted-printable)>]
> On 1/20/20 4:55 PM, Greg A. Woods wrote:
> > I've always just used "set ignoreeof" (first in Csh and later in
> > Ksh), but just in my initial login shell (i.e. set in ~/.login), to
> > prevent ^D from logging me out.
>
> It sounds like you're making your initial / login shell behave
> differently based on the shell level.

More like the other way around -- all sub-shells behave differently
based on the fact they're not login shells.  Note I also considered (and
still consider) all initial shells in each "window" to be a "login"
shell.  In the days of "layers" (e.g. on the DMD5620) I did that by
inspecting the environment to look for clues that the shell was started
by "layers", but ever since X11 took over my life (and my DMDs have been
scrapped and/or put into storage) I've used XTerm's "-ls" option to make
the shell a "real" login shell.

The $LEV (or $SHLVL) value is just an indicator, one that I only ever
used as a visual cue/clue.

--
					Greg A. Woods <gwoods@acm.org>

Kelowna, BC     +1 250 762-7675           RoboHack <woods@robohack.ca>
Planix, Inc. <woods@planix.com>     Avoncote Farms <woods@avoncote.ca>

[-- Attachment #2: OpenPGP Digital Signature --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2020-01-21 23:39 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-19 21:22 [TUHS] Shell Level Grant Taylor via TUHS
2020-01-19 23:21 ` Thomas Paulsen
2020-01-20  8:15 ` markus schnalke
2020-01-20  8:39   ` Kurt H Maier
2020-01-21 20:42     ` Grant Taylor via TUHS
2020-01-20 19:40   ` Theodore Y. Ts'o
2020-01-20 23:51     ` Terry Jones
2020-01-21 20:44     ` Grant Taylor via TUHS
2020-01-21 23:10       ` Theodore Y. Ts'o
2020-01-20 23:55   ` Greg A. Woods
2020-01-21 20:46     ` Grant Taylor via TUHS
2020-01-21 23:39       ` Greg A. Woods
2020-01-20 23:43 ` Greg A. Woods

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).