Re: Variable expansion inside of functions

Bart Schaefer <[email protected]>
Newsgroups gmane.comp.shells.zsh.devel,gmane.comp.shells.zsh.user
Message-ID <CAH+w=7YnhRNMgfTthAL=Tdd7VPGFETJMMe2D6SA1z46fxs4Bzw@mail.gmail.com>
On Sat, Apr 18, 2026 at 6:53 AM Aaron Schrab <[email protected]> wrote:
>
> might be clearer to have the loop just build up a $cmds array (I'd call
> it $commands, but zsh already defines that)

You can bypass that if you use
  local -aH commands
but clearly you don't want to do that here because you're using
$commands to check existence.

> () {
>    local -a cmds
>    for i in pdfgrep rg
>    do
>      (( $+commands[$i] )) && cmds+=$i
>    done
>
>    $commands() {

Pointing out this is a typo, it'll create a wrapper for all/every
known commands.  Should be $cmds

>      # build $arg
>      command $0 $arg
>    }
> }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.