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

Re: Variable expansion inside of functions



On Sat, Apr 18, 2026 at 6:53 AM Aaron Schrab <aaron@xxxxxxxxxx> 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
>    }
> }




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