Interesting $0 Problem

Arthur Chance freebsd at
Fri Oct 28 16:02:06 UTC 2016

On 28/10/2016 15:40, Tim Daneliuk wrote:
> On 10/28/2016 03:34 AM, Arthur Chance wrote:
> <SNIP>
>> Prepending a dash to a login shell has been standard behaviour since the
>> BSD days at least. I think it was in version 6 of the original Bell Labs
>> Unix as well, but after three and a half decades my memories for such
>> details are a bit hazy. Anyway, it's a standard marker.
> Thanks to all who took the time to answer what turned out to be a really
> stupid question on my part.  It's odd that I've never run into this
> in over 3 decades of working on *NIX ...
> So now, can someone perhaps answer a couple of other really dumb questions:
> When is it useful for a script to know it's running in a login context vs.
> a child of the login shell?

When you want to automatically fire up ssh-agent or X or screen/tmux, or
any other program that only makes sense to start once per login.

> Is there another way to determine if your current shell is the login shell?

csh/tcsh sets the variable loginsh only in login shells. I don't believe
sh does anything special.

> This is more intellectual curiosity than anything ...

Nothing wrong with intellectual curiosity. It's the people without it I
have problems with. :-)

Schrödinger's cat had 18 half lives.

More information about the freebsd-questions mailing list