Hi
Am Sa den 18. Apr 2026 um 14:53 schrieb Aaron Schrab:
> >Is there any way to evaluate $i inside the function definition; but
> >only that variable?
>
> As far as I know, there isn't a way to do that.
I tried with an eval but that is horrible.
> Are you trying to do this only in zsh, or are you looking for something
> that would work in bash as well? For just zsh, unless you've unset the
> FUNCTION_ARGZERO option you should be able to use "$0" for that inside
> of the function definition.
That is an idea. Works that way.
> Also, unless you've unset the MULTI_FUNC_DEF option you could also
> eliminate the loop if not for the checking if the command exists. It
> might be clearer to have the loop just build up a $cmds array (I'd call
> it $commands, but zsh already defines that) of the ones that you want to
> wrap and then define the functions outside the loop. I think which way
> to do it is a question of taste.
I didn't know I can do it that way.
> And, with the default options (if SH_WORD_SPLIT isn't set) you can just
> use $arg unquoted when calling the original command. You don't need the
> quotes around $0 (or $i) either. Although I do tend to still quote
> things to keep in the habit, since I often need to write scripts for
> bash or even sh.
Yea, same here. I overly quote stuff, even if not needed.
> (( $+commands[$i] )) && cmds+=$i
Sane solution for whence -p. I did not know $+... And I do not find it
in the documentation. Only ${{+...}} but that is about parameters and
not about arrays.
Regards
Klaus
--
Klaus Ethgen http://www.ethgen.ch/
pub 4096R/4E20AF1C 2011-05-16 Klaus Ethgen <Klaus@xxxxxxxxx>
Fingerprint: 85D4 CA42 952C 949B 1753 62B3 79D0 B06F 4E20 AF1C
Attachment:
signature.asc
Description: PGP signature