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,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 20670 invoked from network); 6 Oct 2022 19:29:12 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 6 Oct 2022 19:29:12 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1665084552; b=YFjFdjdHdLXPZ1kd6IVN+SACR/ICBK3LZ8VLVukHglnoOVzFq62aGujS3mJ26Y97W9G4/S87VM QqYTpjz43dDl4DEo8okBQXesoVBSXm3ZH3X6AHmvTl7tJNgHG9m+kGV7knvZxveWS14+uAIQUB 5pT9dsVtfOzgwmmMCQfvnrRNItIPmXgA6ogYDc7UOb0LseVT1FURAMCYYLmnpt7LcCkhXjIc2F p9zpLXzijbGHu1cpusE76MLIceDWKXNDezzXu/+FMYw6a5i9qK7CVcxrsTToLhSjULT/pV7t2X d+6XIU9L9tPLPQDlRF72L9iKbGB1IiODJWhtBO+S1sq7xA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (smtpq1.tb.ukmail.iss.as9143.net) smtp.remote-ip=212.54.57.96; dkim=pass header.d=ntlworld.com header.s=meg.feb2017 header.a=rsa-sha256; dmarc=pass header.from=ntlworld.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1665084552; bh=ogD2x2a1VD9468PX7NXjUkkUbWzQrIC3sDuHl9ijJFI=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:MIME-Version:Content-Type: References:In-Reply-To:Date:To:From:Subject:Message-ID:DKIM-Signature: DKIM-Signature; b=oJB1PssL1yqLs0S4qmC3FWUor7fjGPdlMjsk+vyEX09JwZO7WQv8+sTOi26TU+/DlP8ZI4vwV4 P+zeGiNIZkPu8hWa9RpUnv7EUJnUtdlIv5QCqFLv0pVuMPynMb/GjttBL3wSpar37dvlBe6zm6 xOd0bOk4zOOBoMSRPswA9dtAu9Yvqu4MpLO5cBm6S9Xi7pbOdcRg288KgNSiKEGLDlUrlI6Fwa gVjh9REwyxGuI6ss3coV7X1whk7A8Um8wKrFx0xaKz76qqiRs+IXKvIzMFCu/bSLzSpvwPt8k/ ndWUSNj8cQGFv9HfYxD7RWph4e+ftU1csT2pC6cxo8xkAQ==; 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: Mime-Version:Content-Type:References:In-Reply-To:Date:To:From:Subject: Message-ID:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=Ap0tmUZCykYzoqrCYMrbCUpQVzVsHIOUY+klBqKMk+c=; b=bmAw5COSYqZ/K1kEsG1bfhGHfz mH/Z2B+TVCJ5WAzi455TJSQD9lfOSwGuCNkAtFnz58OpUyO7SGuaNRnVgFKoZpNQTiWv1A/lBdUib wt3jx3tG5nDm5OyGIYvqlT3Pmb0fPjdCcIf7SY2AP/u2o5D+OC4bEx/cCXlvp7AMm761A/9eu61q8 12vghGP9n4crKeu1ocrQqCICM6hq7y0CcezbkqlWtqrLcENqwr3j6Ai8Jsqy1u1O313FcAfevEp1i 5xOrQYp+9UmA48A4HbMDup4n8I1We+vQgie99BENAaa8Y/SR5RIrcQ/Ikl6jhBY20Y7YXIPp3Xuoi dyI29O2Q==; Received: from authenticated user by zero.zsh.org with local id 1ogWYS-000PQ0-77; Thu, 06 Oct 2022 19:29:12 +0000 Authentication-Results: zsh.org; iprev=pass (smtpq1.tb.ukmail.iss.as9143.net) smtp.remote-ip=212.54.57.96; dkim=pass header.d=ntlworld.com header.s=meg.feb2017 header.a=rsa-sha256; dmarc=pass header.from=ntlworld.com; arc=none Received: from smtpq1.tb.ukmail.iss.as9143.net ([212.54.57.96]:60758) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1ogWXR-000Ohr-Kj; Thu, 06 Oct 2022 19:28:10 +0000 Received: from [212.54.57.111] (helo=csmtp7.tb.ukmail.iss.as9143.net) by smtpq1.tb.ukmail.iss.as9143.net with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ogWXR-0008Ue-Ab for zsh-users@zsh.org; Thu, 06 Oct 2022 21:28:09 +0200 Received: from pws-Zeus ([82.1.229.179]) by cmsmtp with ESMTPA id gWXQo1wdh01WJgWXRoc3gh; Thu, 06 Oct 2022 21:28:09 +0200 X-SourceIP: 82.1.229.179 X-Authenticated-Sender: p.w.stephenson@ntlworld.com X-Spam: 0 X-Authority: v=2.4 cv=KfDBDCUD c=1 sm=1 tr=0 ts=633f2c49 cx=a_exe a=W4rGJ7PGCSRRUvufKHO8Dg==:117 a=W4rGJ7PGCSRRUvufKHO8Dg==:17 a=IkcTkHD0fZMA:10 a=Qawa6l4ZSaYA:10 a=2B-Oc0_MyWyZiqaFygsA:9 a=QEXdDO2ut3YA:10 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ntlworld.com; s=meg.feb2017; t=1665084489; bh=Ap0tmUZCykYzoqrCYMrbCUpQVzVsHIOUY+klBqKMk+c=; h=Subject:From:To:Date:In-Reply-To:References; b=nnuyzmBXTOjicJJX6H/jEHy+dLgumoZLYjOVbytuWQPi8xdCEwtLMkP7rH72vSNm+ 35rHk0ZwcPXcmM2LqzS4vgq3sltglzOhzK6jH4eUCmnTvLH5nTRjyuEZ0/0soWFgYZ QGj4X8gyYmqv3T3rzWyextD9LZ25wwUeoxQKeZnijtpilqFxDvZJgo/brgrJf+mOzl 4NxQ7JQgkq1tHYhdGS8kXv6NXFrMUy1NQIEWwO+B/Mp0Nha5PGywl6GcY1EUtJGDor 7TRw46447f9VPcx58trFdLbCWBkgmSiPW+KVYVhkpA5eJ83dOY+SfdXXwQaGrV5mGM +QeQuOu7ISkZA== Message-ID: <3bf17a2cc56cbc65fc0ba855fe9c7d2d2f63befb.camel@ntlworld.com> Subject: Re: unexpected unmodified variable From: Peter Stephenson To: Zsh Users Date: Thu, 06 Oct 2022 20:28:08 +0100 In-Reply-To: <1774a1bc-c353-4e16-80a2-0082457de6e0@eastlink.ca> References: <1774a1bc-c353-4e16-80a2-0082457de6e0@eastlink.ca> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5-0ubuntu0.18.04.2 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-CMAE-Envelope: MS4xfLYrSqVhq/VTAj8zMbmp4Y1rJ+946HuRP6TCBXzjfz//D6Es5+mg029WTUNnjxBeQ0bwGKuJgLOfzgDMyjWpT5mLbzx0LDQQEMBQdGZBmKNARw98qwMH 3R7CnDd55RmxrJCEd7qJopIWYhS4oyQjmfFUEA4BBKeTIen6uaRerCLh+cgyh83dR99WGmOncWucPg== X-Seq: 28192 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 Thu, 2022-10-06 at 12:07 -0700, Ray Andrews wrote: > ... This catches me by surprise; when " var =$( func2 ) " happens I'm > expecting 'func2' to do everything it does including reset 'count' to > '2'. Why doesn't it, and is there any way to solve that? $(...) causes a shell to be forked --- it runs in a different process, prints its output to somewhere that's collected by the main shell, then exits. So the internal effects disapper. There's no simple workaround if you want the output directly other than what you tried. You can make the function set a variable instead. % foo() { typeset -g $1="this is returned from foo"; } % foo myvar % print $myvar this is returned from foo The -g in the typeset tells it not to create a local scope within foo. Returning stuff in a sane way is a real weakness in shells. pws