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=-2.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_BL_SPAMCOP_NET,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 12670 invoked from network); 5 Apr 2023 18:17:21 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 5 Apr 2023 18:17:21 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1680718641; b=CaCfJzNjNZtby2e9hTyh5dG96/UxdewXrX/SaNVEggkRLIqnKDKuiWdAr/gLF8I8bUo4MO8aP/ OeMSG9/24ka30N4hHjci93Qiz0CVzcsz08fOu4cjYhlTgItvyBAD7nj6s1dYT1J0OvyGQqc2+2 xnRlxsiNTVoEO/Tft5RBVcrZHccq5yfC+15CZmVBiZcQpaVp0A/UawvDo6MYigNk8OMIYDHX5c 8fZHnzVmaC7sQiuic1GDzRwDBI4tjYH8sRih4tChzbextCfw6QFYUpXPBkE4Aod4slBOI7Oxml 7ga8AW6AbhKtlbjqzKYUIhe0UBSKbuvVmgt4iLegLFAOZw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (snd00009-bg.im.kddi.ne.jp) smtp.remote-ip=27.86.113.9; 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=1680718641; bh=K2IJYDw1jRXZieAdCqioO+hkkMtRxnEtEdbI4/NM6h0=; 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=kXtlTwfmXGuWm/u66QRzfAeGnlj0HYz7eWrBdchxtux2Ng2Tq2+CVj0IfE8rH3DYEEOasMUux6 6H8qhOfyBUd8oW6laGXQu6CyO+dt0fNglPY/SF+WrCy/cIJEc84L0RBxG2NgoJDmKqANe1bYkZ 3gSXJ7wGfwl8a3MK1043AedaGlypo0Ku5OVrsNfAscw1sFZzAVoN13L1TLqh68a1XKPE/HvHB9 LrvUE1h2Tj7nqBal5nZDtzwy7ku4O8M03v8OBJxcpMjeaEtehZjBxbklcd0IyLjjOdLUvwc+n5 Q3F8fWkBkgNjXg31PQMRaClS6zdxEHIztE9ZgFEG3Cfq/w==; 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=zPohU5YfHn0PMOhBAZg59s8SryGZmW4pHHAdAZQ+YEk=; b=GkRljVEZ+WoflQPFt/1p3AYycM MKJJjyGTegOgA+jAr8Ywt2YlTQGFM5QqG4CsDHRDrccipw63A+iZDmcIZqS3v0m6uoBWzL/vK86+n ul6CikgrjGi34pOCWbvQYdduC/X0qCnb59WjcrEt+4fWlXoSXgkF9oQZg45mfYk6PbAq7APayH3cJ lFOG2/kGuqIQcYEsOUNddTzOklXAaK9Rkyqaz34B41fV7fj3Wi3b7RkbYyKAlm1yuvhum+iAMyJGZ SU8RxVIBLj4SUHDOjZK8Z8YDv7rcLPI5/qP21H4yYLkm8TJyr3yNUVUfzRBkC74XqbRA9vUEDaFoI 9QtfWU9g==; Received: by zero.zsh.org with local id 1pk7hA-0005Wn-BK; Wed, 05 Apr 2023 18:17:20 +0000 Authentication-Results: zsh.org; iprev=pass (snd00009-bg.im.kddi.ne.jp) smtp.remote-ip=27.86.113.9; dmarc=none header.from=kba.biglobe.ne.jp; arc=none Received: from snd00009-bg.im.kddi.ne.jp ([27.86.113.9]:53601 helo=dfmta0007.biglobe.ne.jp) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1pk7ga-0005D8-Du; Wed, 05 Apr 2023 18:16:46 +0000 Received: from mail.biglobe.ne.jp by omta0007.biglobe.ne.jp with ESMTP id <20230405181638514.LDF.39797.mail.biglobe.ne.jp@biglobe.ne.jp> for ; Thu, 6 Apr 2023 03:16:38 +0900 From: "Jun. T" Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.2\)) Subject: Re: ksh compatibility: initial value of $_ Date: Thu, 6 Apr 2023 03:16:36 +0900 References: <2A0716F2-F80B-4357-87AA-0A9881A52CEC@kba.biglobe.ne.jp> <838816ad-0337-452b-94d1-e18a17c33c78@app.fastmail.com> To: zsh-workers@zsh.org In-Reply-To: <838816ad-0337-452b-94d1-e18a17c33c78@app.fastmail.com> Message-Id: <739C36BD-E3A5-40A4-B661-2AC54D32C2C1@kba.biglobe.ne.jp> X-Mailer: Apple Mail (2.3696.120.41.1.2) X-Biglobe-Sender: takimoto-j@kba.biglobe.ne.jp X-Seq: 51631 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/04/05 17:14, dana wrote: > would it make sense to revive the idea of having a dedicated variable > for it, Yes, I've been thinking exactly the same thing. If we add, say ZSH_EXEPATH, then I think just copying _ from envionment = is enough. # For the script name, if ZSH_SCRIPT is not an absolute path, then we = can # use ${ZSH_SCRIPT:a} before cd-ing from the initial directory. The following is the patch for initializing $_ from environment. If this is OK, and if ZSH_EXEPATH (or any other name?) would be usefull, then I will try to prepare the patch for it separately. diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index 528c27f93..07529aa35 100644 --- a/Doc/Zsh/params.yo +++ b/Doc/Zsh/params.yo @@ -779,7 +779,10 @@ last pipeline. ) vindex(_) item(tt(_) )( -The last argument of the previous command. +Initially, if tt(_) exists in the environment, then this parameter is = set to +its value. This value may be the absolute pathname of the current zsh +executable or the script command file. +Later, this parameter is set to the last argument of the previous = command. Also, this parameter is set in the environment of every command executed to the full pathname of the command. ) diff --git a/Src/init.c b/Src/init.c index 68621a0ad..7e98af44c 100644 --- a/Src/init.c +++ b/Src/init.c @@ -1084,9 +1084,12 @@ setupvals(char *cmd, char *runscript, char = *zsh_name) ztrdup(DEFAULT_IFS_SH) : ztrdup(DEFAULT_IFS); wordchars =3D ztrdup(DEFAULT_WORDCHARS); postedit =3D ztrdup(""); - zunderscore =3D (char *) zalloc(underscorelen =3D 32); - underscoreused =3D 1; - *zunderscore =3D '\0'; + /* If _ is set in environment then initialize our $_ by copying it = */ + zunderscore =3D getenv("_"); + zunderscore =3D zunderscore ? metafy(zunderscore, -1, META_DUP) : = ztrdup(""); + underscoreused =3D strlen(zunderscore) + 1; + underscorelen =3D (underscoreused + 31) & ~31; + zunderscore =3D (char *)zrealloc(zunderscore, underscorelen); =20 zoptarg =3D ztrdup(""); zoptind =3D 1;