From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id 8D9892A356 for ; Tue, 12 Mar 2024 21:07:26 +0100 (CET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1710274046; b=qaUO0mWRlvBPFDep9YJR1C8f5fcc+/u7inCxWNfQgQ+fw/iLLl57Cemzr1yhBmRDmS7rpf2OGe LC1ow+n+QJ27zSfhJRBfcn+O7zICu+1PmmsjMuNokYK51wUH6FenuTsaCL9e9l7qzhKPzUlv5T SqgESucn2VlCsJVFxjOSjjd1hxOLKNvQp7qC1bmrVNq75r3yGT9QXU8t69OZnCdpNfoQk3q7q5 KsfWxelXXMy5b8uzk2sNzLB1/Qfrgi/QAzwsqTp4REp6xVjiwfV57stHEBx8UJ1Hj+pHg0VWmN Rx83qErM1GS040lwiK+B4f3pgMjuX1A7U5JWbv9RSPTzPw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (relay4-d.mail.gandi.net) smtp.remote-ip=217.70.183.196; dmarc=none header.from=chazelas.org; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1710274046; bh=pI+2yPQvcs+jdcAh7UI5hBD9jya94jDXF2B4pVNCu+k=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:DKIM-Signature; b=ocNHJZTuqlb+Dbc1nSqz6Up9WNSWeB8lJpZ2RYaDDyCbFYQAA3xWewm1P6zaHPRrtkpkcT1ph6 aHTzJBcxfoJzEUByO+EcTdk+kjEFMbmL7Tz8gmiFgI/9axGjUrsbgV4eyYm2U3NYInj+1mJCNt 8vd1He21uEWYvIRyCN2wXJXotEcTa3+aHgQKIgZsaE6uc5QoRQof+N+YvWN8MKY8HZ7eX9hQLr oz/HUjvT2IoDC0DhCc2Yjp3p0yYYP2HPMeXmC8seH8+NsRyK6HpX7BBqGHYAplo5gibZ4c6hEo wkPJLmXLwtcVaGHjLQ2g+J/88x/OIOFlZjrSEhrr/U26gA==; 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:In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=RXBV52ykd6uAAzND1uyVTkjAESXEtYHQ42XZbsrbTZI=; b=hnUEsRjRYmVh9KVmF81SxAAqjj GSSdOwBCCWhZsPovVvzvZ+bE7EDWut0a0zi4YZoQT3oOW5AA+pHgqlwGCGh+MH2qSLWQLaG6od7Wy 3N9gjagPRo5xXOYMLLH3iGbmkVdmUZUkdeA1OYznOMvLXhIMWhI8ja4o26ae3UMMWzrNhJwiPe/uw nPWG0kvL622OkKVxCecyQQ527KuJlr5lgOOvZdkARilG7tnu+CGq+DrUbr6M/I/WNpL3a8OsRQGcw nYaedBg1VQ/xV173W11aFLKM+pCvs+RaJGri60TErgKKXQsenOBP/Z4J8cVRhoskWo//FjtaL64qL qXMPbDdQ==; Received: by zero.zsh.org with local id 1rk8PF-0004dY-At; Tue, 12 Mar 2024 20:07:25 +0000 Authentication-Results: zsh.org; iprev=pass (relay4-d.mail.gandi.net) smtp.remote-ip=217.70.183.196; dmarc=none header.from=chazelas.org; arc=none Received: from relay4-d.mail.gandi.net ([217.70.183.196]:57139) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1rk8Of-0004Jo-4E; Tue, 12 Mar 2024 20:06:49 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id D96E9E0002; Tue, 12 Mar 2024 20:06:47 +0000 (UTC) Date: Tue, 12 Mar 2024 20:06:46 +0000 From: Stephane Chazelas To: Bart Schaefer Cc: Zsh hackers list Subject: Re: "typeset -p" and no_GLOBAL_EXPORT, other misc. Message-ID: <20240312200646.znbo4dw3rocza335@chazelas.org> Mail-Followup-To: Bart Schaefer , Zsh hackers list References: <20240312084926.d6vbk75ozud7i2jm@chazelas.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-GND-Sasl: stephane@chazelas.org X-Seq: 52732 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: 2024-03-12 11:32:41 -0700, Bart Schaefer: [...] > > bash-5.3$ f() { local i; integer i=2+2; echo "$i"; } > > bash-5.3$ f > > > > bash-5.3$ echo $i > > 4 > > > > That "integer" changed the type of the global (outer-most) i > > variable instead of that of its caller. > > Looks like "integer" et al. in bash actually search for the parameter > using the type (which corresponds to what zsh attempts to do when > using -p), rather searching for the parameter name and then altering > the type (which zsh without my patch sometimes does by accident). > > Does it always use outermost scope or does it just use the "nearest" > integer (in this example) that it finds? Sorry, you're missing my point. bash doesn't have an "integer" builtin. I was defining a: integer() { typeset -gi "$@"; } *function* to demonstrate the undesired behaviour of bash's typeset -g. [...] > > ksh93 does static scoping > > As someone else pointed out elsewhere, this depends on whether you do > foo() { ...; } > or > function foo { ...; } > but really, I don't care, as we don't emulate this bit anyway. Yes, Bourne-style functions in ksh93 do no scoping at all whether static or dynamic. If you use "typeset" in a Bourne-style function in ksh93, that will affect or instantiate the variable in the inner-most Korn-style function in the call stack, or the global scope if there are only Bourne-style functions in the call stack. Calling a Bourne-style function in ksh in effect is like dumping the body of that function on the spot when it comes to scoping. That has its uses to work around the strictness of the Korn-style statically scoped functions. You could do for instance: int() typeset -i "$@" there. > Aside: Shouldn't IGNORE_CLOSE_BRACES be set in ksh emulation? It > currently is not. I'd say $ zsh --emulate ksh -c 'echo go}' zsh:1: parse error near `}' $ zsh --emulate ksh -o ignoreclosebraces -c 'echo go}' go } Are both wrong for ksh compatibility. $ zsh --emulate sh -c 'echo go}' go} ~$ zsh --emulate sh -c 'set -o' | grep brace braceccl off noignorebraces off ignoreclosebraces off ~$ zsh --emulate ksh -c 'set -o' | grep brace braceccl off ignorebraces off ignoreclosebraces off $ zsh --emulate ksh -o ignorebraces -c 'echo go}' go} But that disables braceexpansion (which is or is not enabled by default on ksh depending on the implementation, version, how it was compiled and the setting of the braceexpand (and posix in ksh93u+m) options). Newer versions of the POSIX spec allow (but don't require nor specify) brace expansion, so it doesn't need to be disabled in sh emulation any longer (but doesn't need to be enabled either). Same for {fd}> ... See https://www.austingroupbugs.net/view.php?id=1193 -- Stephane