zsh

zsh export env var with dynamic name


Adding this to my zsh config:

set-vars() {
  list="one two"
  for envar in $list
  do
    export "$envar"=$1
  done
}
$ set-vars orange

and getting error:

set-vars:export:4: not valid in this context: one two

printenv one or echo $one doesn't return anything

I saw someone do that in bash config is it not possible with zsh? I thought zsh was more advance than bash not less.


Solution

  • Solutions from @gairfowl: