From owner-freebsd-questions@freebsd.org Fri Oct 28 08:45:29 2016 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 7832CC24385 for ; Fri, 28 Oct 2016 08:45:29 +0000 (UTC) (envelope-from freebsd@qeng-ho.org) Received: from bede.qeng-ho.org (bede.qeng-ho.org [217.155.128.241]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "fileserver.home.qeng-ho.org", Issuer "fileserver.home.qeng-ho.org" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 1BF7AA6F for ; Fri, 28 Oct 2016 08:45:28 +0000 (UTC) (envelope-from freebsd@qeng-ho.org) Received: from arthur.home.qeng-ho.org (arthur.home.qeng-ho.org [172.23.1.2]) by bede.home.qeng-ho.org (8.15.2/8.15.2) with ESMTP id u9S8YQ6g021793; Fri, 28 Oct 2016 09:34:26 +0100 (BST) (envelope-from freebsd@qeng-ho.org) Subject: Re: Interesting $0 Problem To: Tim Daneliuk References: From: Arthur Chance Cc: FreeBSD-Questions Message-ID: <516bc76f-f14c-e9a5-a246-2e915a5369ce@qeng-ho.org> Date: Fri, 28 Oct 2016 09:34:26 +0100 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Oct 2016 08:45:29 -0000 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.