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,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 24137 invoked from network); 30 Aug 2021 19:31:03 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 30 Aug 2021 19:31:03 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1630351863; b=LQHK44USXnD+NtcmmI5eSEIK7R59Dj/CA0jB/1oFOjGKKsv7dpwbkW3PBUE7xU1x9jb0mIErig P/DvgpTWJr6T4y0pwVpjuaSSfEkoPtjzQnI/T4MIrJn929dslQoKHSGZNZw0LmOVXyEmId4sqj UhfZYx7WxkLBoVK0oAsCUlqdz2La8X9UZsicEZ63AB1OCu/LifYWbw9oEBfBhiSIOC4LHeM5Jd Jo4QpQYU2sCKMqXEwFz3foDBpBeioiBw+O6toe96atChALO4R/zRjdIlIbNyRXIdDORWrl1/fR Lmf7IMAxUHtUINTBFSz6m9KQSrXvd2h5FHEXo39IPlwfEg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-vs1-f44.google.com) smtp.remote-ip=209.85.217.44; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1630351863; bh=tCcha6rQhRW9V+E7gn+0xmYaWr0wfhYtnJRV5CP6GdE=; 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:References:In-Reply-To:MIME-Version:DKIM-Signature: DKIM-Signature; b=Y/F6o2rc0Bd/ietr6rYk0qOv9uFQD2uYMs4+URpi+vvwcAvef7zReXDYusyEptWSyHCsD24Gd/ owlX9klOSHRyylWCE+r9LtCZq8GaoYQgjF/NujP40fAdEbWDbXKOx2/Tgrv/kgx7+rtx9MHgHZ Upwd2Bep5po6/Q5ZuW+MSy+rL2zXiP03oEo1qmqSDXeyIWrMLWa4hCZEyJvEg7rXx+Au+esYfs HvXcmAJp/M6p0xLKNi9iHu6bZtBF7emczbdPQlwNLOVkrq9uKyOcHwE0jwGaP+7U+Wq2QlORtF uCfDCnHKAmQDX4QHWoiOswzBTIA33zKqPEKcBGajdUzfbg==; 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:References:In-Reply-To: MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=/dt5iU+LhtyLJZWwyADwurWZ5OF7t7X8eHZIFiIG9hM=; b=WdzrjqgqJqSHW9hDfn7uUoZ7Ts sO26DaSPOMFldDqbtm9zfocvdDh8SEAWAZ8MMgpah8fLd2iX6j/AjxVYKjbuKEHXQCPrOlyfw68yc AdT2K+qLbydseteZ7vCEd8Wm/EVBuyvcXjyRQ9CqyWVDb2KHFu+lmYLbN57E8spE/bgIhYlBPPZci DSU4SIM0NbsZmDe0usVx+1yTU2jVFxJwBlUh7dGR5OeDYDBcZyRPLxFjoLHIDoK5uFCuwJK1JxKkb LLy+EL4MG7OX0B/GYfYbvZEI28GNegnRzvCMMnSlsPzv0GoA8ZH7bNqou1bpvpwspTv4pcKEQi4VR 3ztETDFg==; Received: from authenticated user by zero.zsh.org with local id 1mKmzn-0000JP-QK; Mon, 30 Aug 2021 19:31:03 +0000 Authentication-Results: zsh.org; iprev=pass (mail-vs1-f44.google.com) smtp.remote-ip=209.85.217.44; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-vs1-f44.google.com ([209.85.217.44]:38823) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1mKmz8-000Pa8-D5; Mon, 30 Aug 2021 19:30:22 +0000 Received: by mail-vs1-f44.google.com with SMTP id a25so3038279vso.5 for ; Mon, 30 Aug 2021 12:30:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=/dt5iU+LhtyLJZWwyADwurWZ5OF7t7X8eHZIFiIG9hM=; b=c1Talx0J8fim00KBkJ9PteMXBiHT7ycP9kB+/ig7mt9PSLQ77RFDnaVvq7XF+aRg6n 4K5iRzWWMo/2FuHG4XyRuuL5h5MR1soKD26YSPug9YVl33lUaZVz3cgp8/Zi7tWCaHPl +BTknwDI9lDrj9TLjQ8sKA00Ldofug5N63V9d0+Ij1ud4LhjB4ZMwtm0SMQw4WxCt1tP 5nNL5oca9eaeVVAeCdmlnnkrcQQJKkr0+R/K3plcQEnBZqpAFwbYDMt3Kx1FMOe534DO s94o9GxqI/jVkRBO9EDjybkGnqzLcBkivFCamgFkeX+caZpOsPnfCqhANUFUx0AycO0I qT6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=/dt5iU+LhtyLJZWwyADwurWZ5OF7t7X8eHZIFiIG9hM=; b=pT45uuu+XpJQSNuMTqlk72SxS5qvB2NGYn4JiOyi4FIO+IT2PV7pSanpoLd2nmsvHq AVGmIUI9Q/mSSRaSRYdgOsrmC9WpW4aCCnvt7L1xlP4Bv8/W27Hzr3EKGrHUkFFWqUuz 4o4TCk/R3xdJTvcy1JVS+ZkItJ0IMc0ks5qIVjrCS3Dr/vSrcGHnbcgesbMOJuycybsO 0jktcfQEVYjF7eKNi3TCRuW4UQRpL0o395fDzWRqUS/He2QdcdN1+DMBZ5+bXzsCYhut Va2ezzvdxw0cJpIuP6UkNBIVq/tfdbbtcrhbBfB9WC5262Prcv9z9LoohZsRuQt30NgK gn4w== X-Gm-Message-State: AOAM530xr2NqXlICOzbAprysD8ru+qloL7Io2tcQMz7xXSibgkPuoILX mkSsVSJrHRvv3dvt8eiQT8weDcXKcpELInoPIVs= X-Google-Smtp-Source: ABdhPJyTCK5TxzR7fI11bJxil3BDvH0+cFZIL39muXtumNdhmGFk9IJEOrutVAME22yRTx74OoaOybeWOaGO95eoo9Q= X-Received: by 2002:a67:eb45:: with SMTP id x5mr16385958vso.19.1630351820876; Mon, 30 Aug 2021 12:30:20 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:ab0:60b2:0:0:0:0:0 with HTTP; Mon, 30 Aug 2021 12:30:20 -0700 (PDT) In-Reply-To: References: From: Mikael Magnusson Date: Mon, 30 Aug 2021 21:30:20 +0200 Message-ID: Subject: Re: autoload variables To: Anthony Fletcher Cc: zsh-users@zsh.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 27001 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 8/30/21, Anthony Fletcher wrote: > On Mon, 30 Aug 2021 at 12:40, Ren=C3=A9 Neumann wrote: > >> Am 30.08.21 um 17:22 schrieb Anthony Fletcher: >> > For instance, one variable is to identify the default uplink >> > interface >> > >> > export UPIF=3D$(ip -4 r | sed -n -e '/^default/ s/^default.*dev //= ; >> > s/ >> > .*// p;q' ) >> > >> > Useful when I'm debugging the network but not needed otherwise. >> >> Is there a reason you need this as a variable? Would a function >> >> upif() { ip -4 r | ... } >> >> not suffice? >> >> - Ren=C3=A9 >> > > A function would work but then you need to run it every time to get the > same value..... and of course the variable is for other commands. Thus > systemcommand $(upif) > In this particular case anything to do with the uplink interface (eg > dump_dhcp6). I guess the function could cache the result for speed. It's unclear from your examples if these variables actually need to be in the environment (eg, used by the program automatically), or if you're naming them on the command line (eg, some_cmd $myvars). In the latter case, they don't need to be exported at all. This may be an unpopular suggestion (I would also not use it :)), but you can abuse global aliases in the latter case as well, if you are very opposed to typing $(foo) instead of $FOO: % alias -g '$UPIF=3D$(echo 123.12.2.15)' % echo $UPIF 123.12.2.15 (keep in mind the word needs to appear separate from other words and exactly as specified for this to work, eg not foo$UPIF or ${UPIF}). (You also don't need the $ at all if you do this, so you could just call it UPIF too, assuming you don't use this in the literal sense (although if you did, you could write \UPIF in those cases).). If you *do* need these in the environment, and assuming that they don't change very often, you could initialize all of them in .zprofile instead of .zshrc and they will just persist in your environment at no extra startup cost. (You can do this for the latter case too, actually). --=20 Mikael Magnusson