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,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 474 invoked from network); 16 Sep 2022 17:46:09 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 16 Sep 2022 17:46:09 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1663350370; b=eXVK4iw5cjpzL2C/lssWBg/0CdYLXEHeqkzNNzM0cINDecnoJ5uwNgARcKqoOHTmI4KUtKCH1P s2vkmINy03jxDp3/gIBCtjEehfyADc1aAZeyMX8KWKmMqW/hh8FoKKhFz3aNr4bUu+8NBIWQyD iim1Z5eoWCd3vdRGESI/BRfLejZD6k1MscwMZvICw7O1bXz3LzsusUC6woeLU8pbmxanfOUBAV k6XaamLUK39fgCG9aKUHmGVw95inwl+uh6+ncH0JCma7uKkm9wu2TkN43A4EmZR4tA8sOdIndR 5PzqK9fcWrZbpFQIcxSIa5IvuWppUnrZm8NUIn/vPBqCdw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ej1-f51.google.com) smtp.remote-ip=209.85.218.51; 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=1663350370; bh=3fjHTfOoy2WtDHM8Fm/PdXK/PXSpGx2ameNDNbKRego=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=Kt81GshK1+KcHXfm8cw/BzOtFfrV/H6JqsYf9e2Er9e+ugifj3pst4oAg4EMjlQcsPXYE8uzxT f8zeh4Oy4r7tzIwacjkclhqLGFceVm8uqdpuv6YyDk7TQCVa7jQBPje+tZSeegz05GiuuZuI/7 sGCowmmrzRoExXgfrOtgJVENLVJlmT0gLyWIv4JVpXaPC+ZFxtPu+IWfILFnp945RBmk5XTxry AVm5k87JVy3qiWYPYBKXo/KWhsVw3fSQl7vQnKLFEk74iGHv68hYgRfMLtqboRI0hJsU8TsCdq fpETnsfqqOgl/97t+vHYKUItqxhATQPy/05S/gQR4WyZUw==; 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:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References: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=k0ix+DqRjd3FUEBWef8bTu7g4VZ+G4QZYfhSK+hTJ3o=; b=MPNL/i0ljwIYOEfk0/usBEQgNI /JvpwCH9avCpgvAtPRU9BumMaUFKiNvwbf+L8WF7gGgZWtYJ/nNCUevugHGgWmF29m+DOGAt22s+k ZdtySCXSJohN0OMU+ViIEYZdQZjLLjIzt6y0djgP92pSIaX3hP2YzRfyaUD0/Fy1lWYNh4E3+5vRw P56JsX9iz00pICxbHwbpakiDqTnrmiNUpdnjtMrDWl6tNFO2uSl3FCx8U+EM5EcOKsJ6c/BK+k7Ka k1NEiPDuwHoB3vkte5zvv5MKpPQtGE4GsbABMpMfaYOO5Z7k5/7RpxNYfoxXM1bvoTKtsJ+MrPbys bfFpWmlA==; Received: from authenticated user by zero.zsh.org with local id 1oZFPl-0001jz-2r; Fri, 16 Sep 2022 17:46:09 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ej1-f51.google.com) smtp.remote-ip=209.85.218.51; 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-ej1-f51.google.com ([209.85.218.51]:40941) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1oZFOp-000148-GG; Fri, 16 Sep 2022 17:45:12 +0000 Received: by mail-ej1-f51.google.com with SMTP id l14so51136919eja.7 for ; Fri, 16 Sep 2022 10:45:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20210112.gappssmtp.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=k0ix+DqRjd3FUEBWef8bTu7g4VZ+G4QZYfhSK+hTJ3o=; b=0ly2oaD+wD+xBWTBt2YjBXA98rOsFUTE+5mI0o36cj/y9Rgkx7406Q5Of94pQiWCxJ cISqIlLyKuPtkhRn/wV3R5EPTXWYYurrr/fBdKxcCXRPczYk0Katr0O0yvcj+iIn58QD IdKPiWv/JdDHLkzY/WdmwROWmdQv4kWr2hkx9E6r+gvOij5LgnHnmgqfpXT07sBaZkyi wL3fNExN62qYzZbdxu0UCYKwOXsQvNY2bz7ofPf5a6XdVNl1Ym/UtsvuGBVaJOfEVNk0 qnYDq9xAUpXxwezKmvJw6/Ily9cAMJbnjWFMSeYfVsxMBQQUWHmiYIDLeTzt+xi5FT5Z rnvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=k0ix+DqRjd3FUEBWef8bTu7g4VZ+G4QZYfhSK+hTJ3o=; b=KRG4GG7K3y9k7Lx6sQJ37Rq3xoFpEUPKBLVjehzMsNNAyrnuug02f4T7PJKxJpZJd0 d7UlK82FEcLpbaa1CCmESCJOLVVxtuixB5TKkF4WHBGf8qh5ysd8Q69lhTXv/2/Fv3b+ MpcZUgb+hHAqT5FNmZZg4urqBzNBnDp0NEujv4uJhpYH1NR+5MDS2zYCzlhoJ8llxJkt WgmJgLmiwsBLWhNBHS5PuyIXkJmWyBePbgnqhYQumQNPXsB6SDSAMOX4G3pH0Y1hJytG VE3RfuuA9cydvF0IOPD4Qbmz+O7f1p4zpSnlpZI2/d8Ce2sv1IbeoDHTnA0oqDhGnav/ CIeA== X-Gm-Message-State: ACrzQf0Bj7A6P3r00ev5yPO2LlOx7qezAkCayoXCIrckrV2UeMWP6PHs IDkVn+yIPhnRxNSJFWhT4a449ULRHj76eVum0A+ETcSptkmndg== X-Google-Smtp-Source: AMsMyM4M+ju3LrnRnaJfUu2UPhJTwICqhIyztDVJkTVTmgkYfB9VugJdO97UoVm9fLT1hgusturgl5hP8Id+DNM/tHM= X-Received: by 2002:a17:907:802:b0:73d:c710:943e with SMTP id wv2-20020a170907080200b0073dc710943emr4266355ejb.214.1663350310720; Fri, 16 Sep 2022 10:45:10 -0700 (PDT) MIME-Version: 1.0 References: <22a10f61-5f82-9797-4bc9-9082f9371dc7@eastlink.ca> In-Reply-To: <22a10f61-5f82-9797-4bc9-9082f9371dc7@eastlink.ca> From: Bart Schaefer Date: Fri, 16 Sep 2022 10:44:59 -0700 Message-ID: Subject: Re: local but persistent integer? To: Ray Andrews Cc: Zsh Users Content-Type: text/plain; charset="UTF-8" X-Seq: 28099 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 Fri, Sep 16, 2022 at 8:19 AM Ray Andrews wrote: > > integer -x start="$(( $(date +%s%N)/1000000 ))" > > ... I need 'start' to persist between function calls which it does Given that construct, it should not. "integer -x" within a function puts something in the environment (so visible to external processes), but it's still scoped to the function and goes away when the function finishes. > I tried 'unset' but it didn't seem to work. That indicates that you're unsetting the local, but there must still be another global $start that came from somewhere. Use a more distinctive variable name (see below). > it would be nice if it could be local as well since it has no use > outside this function. Unfortunately the base model for shell variables (a form of dynamic scoping) and interpretive function invocation does not lend itself to the form of static scoping that you're hoping for. A second run of a function is just re-interpreting the function source code, not re-entering any existing scope other than the global one. Your best bet is to use something like integer -gH _myfn_start=$((....)) (( $_myfn_start == 0 )) && ... which will create a global variable whose value is concealed, using a name that only your function "knows about". This can be generalized with something like this (assumes proper option settings to make ${0} reflect the current function name): integer -gH _${0}_start=... (( ${(P)${:-_${0}_start}} == 0 )) && ... but that's probably overkill in your case.