-1

I am getting an error while setting an environment variable in .zshrc. Could you please help me understand how to fix it.

~ % export DR=--dry-run=client -o yaml
export: not valid in this context: -o

manish sehgal
  • 139
  • 4
  • 12
  • The marked duplicate ("When to wrap quotes around a shell variable") is not a good match for this; it's about quoting when *using* a variable, not when assigning to it, and the problem it addresses doesn't normally exist in zsh. But the solution is roughly the same: put quotes around it, like `export DR="--dry-run=client -o yaml"`. Without quotes, it thinks you're trying to export the variable `DR` with the value "--dry-run=client", and also another variable named `-o` (which is not a valid variable name, hence the error), and a third variable named `yaml` (with no value). – Gordon Davisson Aug 16 '23 at 05:27
  • Here's a better duplicate: ["bash: export: `-Xmx512m': not a valid identifier when I set MAVEN_OPTS variable"](https://stackoverflow.com/questions/47472391/bash-export-xmx512m-not-a-valid-identifier-when-i-set-maven-opts-variable). It's about bash, not zsh, so the error message is different, but the underlying problem is the same. – Gordon Davisson Aug 16 '23 at 05:30
  • In addition to what Gordon Davisson said: I don't know what you are going to do with the variable `DR`, but consider making it an array. – user1934428 Aug 16 '23 at 05:59

0 Answers0