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 31757 invoked from network); 31 Mar 2023 17:46:02 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 31 Mar 2023 17:46:02 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1680284763; b=IGlmUZQvgY6DddJeQKXrda5Foc96g8Kls3TtBm8LrhxLAXO4MlY4wOsJ5xQIeda6qDMdMjtgVX IbS+C0SkyoUdZwAt1rvzb4lZxrHLNvVI0Lrx7hbEuqFr93UwqpacOUT6WjiqlWjXO9wblamCaT 1YPsvaUKQIwnk9Mt2v9y5qHtQIvz0y/bfqUK5S3ZqdsbmKHpOv+RqCmm48HmLaITdzAxkuSUOQ aa2OwnOESLVEgq6p/BPOmVPRdj1tKl9qeqib+wMkDD2B24r+MBzfnPytnvZ95BimJKqAqckVM3 GkuQ0s/GBr8IU8PbxQVPN6bwk28fBV8+6c+VS0TP+I6mjg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ed1-f53.google.com) smtp.remote-ip=209.85.208.53; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1680284763; bh=s0rTY+DrjU1XZNXQ7AE4wGPKWP+lGN56KWuUlMMuHP8=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:Cc:To:Subject: Message-ID:Date:From:In-Reply-To:References:MIME-Version:DKIM-Signature: DKIM-Signature; b=FGCtFDA0xfKw9NDQAi4K1TFQNIE58e885VIXe3+qA8tkeg06QhD/aEYHlKSEy5eOlvT2zyqc5/ DIGZ2eT/9Fb6swtNV5Gw+Upwk0u8/2cquayGNLNEseTH6PkmiHZkxPJSKUI02UP1k5e8x2EQyw 9IkRpAsIoJ1zh1gGBZEsatKm56o9LJ8nHEhX42K1etsmq2Bu48ClMmsGVmBmBqyTajDWpSSSIA Kwev+K2PSkNsrmoxwmeCYHeRIvVghWL1YBVlxHMsTPkv7AMqJsz7K9dYN29uqjeDja2QXgrQVf oW3rp8H8/hrXDyH8+NUq/4aFYUnGVB3HOsnA6ti0UetgkQ==; 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:Content-Transfer-Encoding: Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To:References: MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=q1KFRlfZLY7U9tKrymNeI2o9ePl9yIPr+Nj8NaSM+pU=; b=MpUeXsaKWGx/FqquIYMHuo1F1Q jq2Hq1i2HvXW0JLnVAh4rBVGrkWTiQFugoe4+62EQWJHAg6MQTsE4zeR8Bqffgu0azToLvfJq5tGo PX3Sq85yUon2i+uA2pYFG/mIdHfAThZbvnozIs0bOvlTqNN9Dh9mIcTagh7vhv+IwTunFTvG1CHP1 Rr00cWdAUZGAK1+XWLiN3QCL6rk0MgNNBB8W9VV9HMHfTcATJ8e266oRdI6Vi7iE+twEUJAzjijFk mX7QoTGRcShUHbZuFCqqPDitbr7I1TH5nhsZhQMgSU+ADHAO9dUvA2toMkqvA5NSjbO74o5k52HNY /s3ir8RA==; Received: by zero.zsh.org with local id 1piIp7-000CJe-3r; Fri, 31 Mar 2023 17:46:01 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ed1-f53.google.com) smtp.remote-ip=209.85.208.53; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-ed1-f53.google.com ([209.85.208.53]:44589) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1piIok-000C1s-Da; Fri, 31 Mar 2023 17:45:43 +0000 Received: by mail-ed1-f53.google.com with SMTP id eh3so92620013edb.11 for ; Fri, 31 Mar 2023 10:45:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20210112.gappssmtp.com; s=20210112; t=1680284737; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=q1KFRlfZLY7U9tKrymNeI2o9ePl9yIPr+Nj8NaSM+pU=; b=3FmHi7NIZYBcoW3W+/9RK2531dByUQnH6I0dBPv89pmd+CGJc9iGtKcSF4vt65w2w3 ZxOwXFQ+mrt6fcBssJR4ckzGDLb9qqXPgfkYPprxJ6XmpVzvE+fSzO+ZpNcIIac2Y+sn bQKLBbsxa3W84G24lmdHPEEJymLv368vaDMsslOegViv3NdQ8MNAtmfG2+OCLkManU3S a2Fg1wvDfkOqMQS348iHpbNEslkoKLfrIDX0N0DQK2+E7Eoc/fu84DljdY5xOD4+XPfp ZI+vGcz6Qy8+WSkH+MrSJmU1B0HVOyqsI95oIYa5tVOccFe6KSV5LU2/Jy7RLQ11De1y jCZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680284737; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=q1KFRlfZLY7U9tKrymNeI2o9ePl9yIPr+Nj8NaSM+pU=; b=q0scZZUUWbbxLUx9kWjRigd1i0arxIs0gZb7ifTGZoGxITSV1HD0+aNGiIaqBxD6SB PngkZ9Cs1iXlyKRcP0H+pzPQS/9T0yVFzEZXC58jZLkyYP5J5VegAQ8Q6P1CEyaR2gJ1 QTpnMGTtJK0mSx0MjR/N4dZFbrjy84+ZBq4ORyyGSiH0vTa9FZZCsUfPQa35UIrWG4mg Z1+6+TyOC1dqZf0NpylnE50ltwgDO2TytLfd6jQ8omKX+CHiNm4xPOYcCg80+x+GvOMi O/2fYV2mA/9J06oTD0/DhvUTMEbKCCK2UYAu6Qo+cSFMtfAcAuoZFxxcQNEMJoVCpQNY RQPg== X-Gm-Message-State: AAQBX9cRl2LE8zgGhAyXZlTlWM3RFl/5Z1Z1c3NGH2DNw9grvq3n1vmf cop8a7hwBA8/b5QKfqUghPjHCTM/Sh+nJg18a1wJEYRpCVgRudszKFM= X-Google-Smtp-Source: AKy350ZpR5UcO/N6QooytQvQntgXwJwNF/ipH4SNpsMU1k789edX3JW6ECNgvrhzRx8FdFSXuKKG612hnR2EMJeosuc= X-Received: by 2002:a17:906:8059:b0:933:4ca3:9672 with SMTP id x25-20020a170906805900b009334ca39672mr14090730ejw.12.1680284737665; Fri, 31 Mar 2023 10:45:37 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Bart Schaefer Date: Fri, 31 Mar 2023 10:45:26 -0700 Message-ID: Subject: Re: ksh compatibility: initial value of $_ To: "Jun. T" Cc: zsh-workers@zsh.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 51616 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: On Fri, Mar 31, 2023 at 7:32=E2=80=AFAM Jun. T wrote: > > _ Initially, the value of _ is an absolute pathname of the > shell or script being executed as passed in the environment. > > So zsh can just do the same thing? > With the following patch, zsh behaves similarly with ksh? With your patch: % /bin/sh $ Src/zsh -fc 'print $_' /bin/sh $ Src/zsh -fc 'echo $_' print $_ $ Similar behavior from ksh, so it really is whatever happens to be in the environment for '_' rather than an actual pathname. This means you only get the documented behavior when a new shell or script was invoked via a previous shell that exports $_ appropriately (which evidently zsh already does, though I can't immediately find the code). % typeset -p _ typeset _=3D_ % printenv _ /bin/printenv % There's nothing in POSIX (that I can find) specifying any behavior of $_ at= all. One other notable difference (which I think has been mentioned before) is demonstrated thus: ksh93: $ for _ in a b c; do echo $_; done a b c $ for _ in a b c; do echo X; echo $_; done X a X b X c $ zsh (even with ARGV0=3Dksh): % for _ in a b c; do echo $_; done echo echo % for _ in a b c; do echo X; echo $_; done X X X X X X % So ... ksh assigns $_ only after each full complex command, and does not otherwise treat it as special, whereas zsh assigns it after every pipeline (and also after the "do" keyword, it seems) and cannot use it as a normal parameter in between. (This can be partly worked around in a function body by using "local -h _" but then all special behavior is lost.) Incidentally, as far as I can tell from a quick bit of research, if you want to compare zsh and ksh behavior it is not advisable to install "ksh2020" (which is unfortunately the default "ksh" for Ubuntu at least as of 20.04). Explicitly install "ksh93" instead if you have that option.