Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 28 Oct 2016 09:34:26 +0100
From:      Arthur Chance <freebsd@qeng-ho.org>
To:        Tim Daneliuk <tundra@tundraware.com>
Cc:        FreeBSD-Questions <freebsd-questions@freebsd.org>
Subject:   Re: Interesting $0 Problem
Message-ID:  <516bc76f-f14c-e9a5-a246-2e915a5369ce@qeng-ho.org>
In-Reply-To: <b859f7a3-51d1-06f4-e793-332edd212068@tundraware.com>
References:  <b859f7a3-51d1-06f4-e793-332edd212068@tundraware.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 28/10/2016 02:30, Tim Daneliuk wrote:
> I was fidding with some shell code today and discovered it was breaking
> because $0 was returning "-/usr/local/bin/bash".   Why is there a leading
> dash here?  I've not seen that before.
> 

This is from "man sh" in the "Invocation" section but presumably bash is
mimicking the standard behaviour.

> When first starting, the shell inspects argument 0, and if it begins
> with a dash (‘-’), the shell is also considered a login shell.  This
> is normally done automatically by the system when the user first
> logs in.

And in the source code for /usr/bin/login

        /*
         * Login shells have a leading '-' in front of argv[0]
         */


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.

-- 
Schrödinger's cat had 18 half lives.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?516bc76f-f14c-e9a5-a246-2e915a5369ce>