Altering zsh's $path variable in a script that is to be sourced
zsh
Solution
By default the typeset command creates a new variable with the supplied name that is local to the current function, so changes to that variable will be lost when the function returns. Add the `-g` option:
typeset -gU path
This will prevent localizing the variable.
Problem
I've inherited a zsh script which sets up a bunch of environment variables for some simulations. It wants to edit the $path variable so that some perl scripts can be found: ``` typeset -U path path=( ${SIMENV_BIN} $path ) ``` However, when I source the script (`source setup.source`) the $path variable remains untouched. If I copypaste these lines to the command prompt, they do update $path. If I sprinkle 'echo's in the script and source it again, the typeset command seems to clear the $path variable. Would someone mind explaining to me what is going on, and how I can fix it?