From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 26905 invoked from network); 31 Mar 2023 08:19:37 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 31 Mar 2023 08:19:37 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1680250777; b=dKuv6+j5yNZmmQxQm3EbqGG5Zfe69rkYVo219uM8PN8OiuTpZvXWbE32st7osL9n44KZBcibLS 2fYJvXz/cTE68t7x2xmG7M8IHmsR2V/RqMf15tvXF49u+6CEpzeCZvbl+EVfVVEKSMMvBlEq95 v7eYke01gkXLIARuw6h9rAR4FQAm3Q5IxhvXOJ/Ytc/kHxonNZxxs6gRHATLI0u0DbdZoovCOR xkWaqOotKcafhK+/VWbyo6hHGNxr1biMtFAt8o4wIWtW225HIZ7pQFnwV0ZqC8RLnNmUU7PApD ht99eX3SoZkhVlIWFBQBEpbggCJoStZ22o4sKsBGnXj9+A==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (snd10007-bg.im.kddi.ne.jp) smtp.remote-ip=222.227.83.7; dmarc=none header.from=kba.biglobe.ne.jp; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1680250777; bh=9jawaVA9sfIzHuqRlurfroKcZDPws0zRSb1z0WtpsLU=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Message-ID:In-Reply-To:To:References:Date:Subject: MIME-Version:Content-Transfer-Encoding:Content-Type:From:DKIM-Signature; b=F0hGuofAxbohbsV2K/ksxUl9r0KW07pRarC3RTpjJwdi0CDYh4b+QAQG61P++3RQVlBIXG01k0 xgUesWK5pk+w3PRs5IjqvyqPKtlsSr2u14bG9r6qc3A1bNj4LhObrWYjOuCb1NU8xx08J8KCSv LgGMJ8ZFf87AZNIdNqiDmkIcAxmSzhGqyuknPsoOuOZQxuIQwEjHByiztTc0PEJOfGkUYh4ah+ lXGPwQhYfLdm9SExzBcv7SXYX3gU5VN6YA/W9d8rGgnxWF3UegMTzjnSFgenLex73Fk6SYuVON jKFSVPfLmmFFniR/4Tryb5k/Lmyv5wiWr7S5uWi5zJaj3Q==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Message-Id:In-Reply-To:To:References: Date:Subject:Mime-Version:Content-Transfer-Encoding:Content-Type:From: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=zAg03/funvBWuuF58Vls0oyu0YhLKsMz3j2B2kO4ZCk=; b=FQex/TWGaqD0CrSgGESu9rtZ2R HHjbovsBSljPyIWHKtnoyeFUusM2d+LAf8O4VlYw3N/jTpaOmr1z3B+yCZiJ+503C+pNPzcNlPbcA kZfFf8FYrg8C4BzdS/LjmeSGisj7rOdUyEMW9dYXFgYyEho0Nu5Sy7DY1enZUza8+wUGmIo0/q10H JYlP4Cb2vQxxEiWZMNoy2ycAjhWwU8HwoylAGtEHhZ19OE+Jb5jJ5kZn4fAgLUV7fYq5PSBzrcSU2 AuRzFgAU3/REWkAxTYgmPR+PukYu1zIdhG7z/kYL4P070L7J9Ku0ZV6ut2daTkBLi+IisUWkVOdO4 d0sCAkwQ==; Received: by zero.zsh.org with local id 1pi9yx-000LSc-S9; Fri, 31 Mar 2023 08:19:35 +0000 Authentication-Results: zsh.org; iprev=pass (snd10007-bg.im.kddi.ne.jp) smtp.remote-ip=222.227.83.7; dmarc=none header.from=kba.biglobe.ne.jp; arc=none Received: from snd10007-bg.im.kddi.ne.jp ([222.227.83.7]:42817 helo=dfmta0005.biglobe.ne.jp) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1pi9yP-000L9f-KT; Fri, 31 Mar 2023 08:19:04 +0000 Received: from mail.biglobe.ne.jp by omta0005.biglobe.ne.jp with ESMTP id <20230331081852517.RRYX.71968.mail.biglobe.ne.jp@biglobe.ne.jp> for ; Fri, 31 Mar 2023 17:18:52 +0900 From: Jun T Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.21\)) Subject: Re: ksh compatibility: initial value of $_ Date: Fri, 31 Mar 2023 17:18:52 +0900 References: To: zsh-workers@zsh.org In-Reply-To: Message-Id: X-Mailer: Apple Mail (2.3445.104.21) X-Biglobe-Sender: takimoto-j@kba.biglobe.ne.jp X-Seq: 51612 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: > 2023/03/23 19:40, I wrote: > >> 2023/01/28 10:52, Bart Schaefer wrote: >> >> Src/init.c explicitly initializes $_ to the empty string. >> >> Any reason not to change this? > > No reason, I think, but I don't know any portable way to obtain > the full path name of the current zsh executable. $_ need to be initialized to the full pathname of either current zsh executable, or the script file. I have some difficulty with both. [1] full pathname of the zsh executable: On Linux we can use /proc/self/exe. By some Googling I've found that Solaris, NetBSD, and DragonFly have similar symlinks in /proc. On macOS we can use _NSGetExecutablePath(). On FreeBSD, it seems porcfs is obsolete. On OpenBSD there seems to be no reliable way? But, for {Free,Open}BSD just guessing from argv[0] and $PATH or $PWD would be enough, although argv[0] can be set to arbitray value in execve(2). [2] full pathname of the script file We can guess it from argv[1] (after removing options) and $PWD, and the variable 'runscript' is set to argv[1] at line 290 in init.c. But, suppose we have a ksh script 'foo' in the current directory: % cat foo #!/usr/bin/ksh echo $_ % ./foo /home/takimoto/tmp/./foo % ksh ./foo /usr/bin/ksh How can we distinguish these two cases? In both cases runscript is './foo', I think. Probably there is a simple way that I just don't know.