Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: autoload variables



On Tue, Aug 31, 2021 at 2:11 AM Anthony Fletcher <anthony@xxxxxxxx> wrote:
>
> I think that using a function that caches the value and then invoked via $(upif) is easiest. Something like
>
>    upif () { export UPIF; echo ${UPIF:=$(ip r | ....) }}
>    tcpdump -i $(upif) .......

Assuming that you don't set UPIF manually anywhere else, this code is
equivalent to this:

  upif() { ip r | ....}
  tcpdump -i $(upif) .......

That export and conditional assignment don't do anything because they
are within a subshell. Anything you export there gets wiped out
immediately and won't be used the next time you invoke $(upif).

Roman.




Messages sorted by: Reverse Date, Date, Thread, Author