I defined a nested function in my .zshrc hoping to define multiple similar zsh functions :
makefunc_gman () {
local MAN_SEC_LIST=(1 2 3 4 5 6 7 8)
for GMAN_SEC in ${MAN_SEC_LIST}
do
"gman${GMAN_SEC}" () {
gdir_C "$1" "man${GMAN_SEC}"
}
done
}
makefunc_gman # calls the function
- The functions I wanted to define the function above are
gman1,gman2togman8. - I want to get a function named
gman1which callsgdir_C "$1" man1after sourcing this function above. gdir_Cin the code is another function defined in.zshrc.
But when I sourced .zshrc, where gman1 gave me this:
$ where gman1
gman1 () {
local MAN_GMAN_SEC="man${GMAN_SEC}"
gdir_C "$1" "man${GMAN_SEC}"
}
It seemed that the variable $GMAN_SEC in this nested function is not expanded. How do I get the variable to expand correctly? Thanks!