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.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 14291 invoked from network); 22 Mar 2023 01:06:02 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 22 Mar 2023 01:06:02 -0000 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-Type:Subject:Cc:To:From:Date: References:In-Reply-To:Message-Id:Mime-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=DiGDOTPlKgoNt8BkQPPU//j5tBbHRGs95vnC9gYHc44=; b=lFRW/mHy7eYlaMrO2H8Fb8qdGB J+E9DLhjYkkU4vYy5MMArpBLyd3fkrAZUlIkEVa454b3G9LC3oXcfq9m2gq3rALfa+OuZexMmWWMe ghYbNHvgb45yEr4RJAJg0RlW4JK1cBlmHcZnrIUugHGGSC2p/TynGxekE5VlnOCc2EQaITRq2V83h mzp1lx0BguA+CpXO7AhJVuLYBdcyeXfQRoZXXRga1Kf1elMNOdCz9R+oLG2wDtcqboCxz1ipUvEfd 8jpHtZs41BsxY2xcG5hJew1lVfovb0EnSvVQ7SOzzTZSHXW8QBeiPPvdeEuNVhLANgsc8K4XPCKiZ FZrUcV2w==; Received: by zero.zsh.org with local id 1pemvS-000Fzg-Mw; Wed, 22 Mar 2023 01:06:02 +0000 Received: by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1pemuk-000FIW-Gt; Wed, 22 Mar 2023 01:05:18 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailauth.nyi.internal (Postfix) with ESMTP id D3E1F27C0054; Tue, 21 Mar 2023 21:05:16 -0400 (EDT) Received: from imap48 ([10.202.2.98]) by compute1.internal (MEProxy); Tue, 21 Mar 2023 21:05:16 -0400 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdeguddgfedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvfevufgtsehttdertderreejnecuhfhrohhmpefnrgif rhgvnhgtvgcugggvlhojiihquhgviicuoehlrghrrhihvhesiihshhdrohhrgheqnecugg ftrfgrthhtvghrnheptedthfdtueefudejvdevieehleeggeelkeekvdegveejudetgeet tdehtdefgedtnecuffhomhgrihhnpehophgvnhhgrhhouhhprdhorhhgnecuvehluhhsth gvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheplhgrrhhrhihvodhmvghs mhhtphgruhhthhhpvghrshhonhgrlhhithihqdduudehudekjeejtdegqdduudelvdejfe ekhedqlhgrrhhrhihvpeepiihshhdrohhrghesfhgrshhtmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: iaa214773:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id A51C031A0063; Tue, 21 Mar 2023 21:05:16 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-236-g06c0f70e43-fm-20230313.001-g06c0f70e Mime-Version: 1.0 Message-Id: <94b397e5-bc81-40fa-b7bf-c7ab9a151744@app.fastmail.com> In-Reply-To: References: Date: Tue, 21 Mar 2023 21:03:14 -0400 From: =?UTF-8?Q?Lawrence_Vel=C3=A1zquez?= To: "Felipe Contreras" Cc: zsh-users@zsh.org Subject: Re: Temporary variable compatibility Content-Type: text/plain X-Seq: 28980 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: On Tue, Mar 21, 2023, at 8:21 PM, Felipe Contreras wrote: > I found a discrepancy between different shells: > > f() { echo $var; } > var=1 f > test -z "${var-}" > > Both zsh, bash, and dash set the variable temporarily, but ksh does not. > > In zsh the emulation of ksh and sh both keep the variable assignment. > > Is this the POSIX standard? POSIX.1-2017 leaves it unspecified, so both behaviors are conformant. As per section 2.9.1 "Simple Commands" (e.g., something like "var=val cmd"): - If the command name is a function that is not a standard utility implemented as a function, variable assignments shall affect the current execution environment during the execution of the function. It is unspecified: - Whether or not the variable assignments persist after the completion of the function - Whether or not the variables gain the export attribute during the execution of the function - Whether or not export attributes gained as a result of the variable assignments persist after the completion of the function (if variable assignments persist after the completion of the function) https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_01 > If so, then how should one temporarily set a variable? A subshell? That's probably the most portable approach, yes. -- vq