What's the difference between set, export and env and when should I use each?
- by Oli
Every so often I'll bash out a bash script and it strikes me there are a few ways of setting a variable:
key=value
env key=value
export key=value
When you're inside a script or a single command (for instance, I'll often chain a variable with a Wine launcher to set the right Wine prefix) these seem to be completely interchangeable but surely that can't be the case.
What's the difference between these three methods and can you give me an example of when I would specifically want to use each one?
Definitely related to What is the difference between `VAR=...` and `export VAR=...`? but I want to know how env fits into this too, and some examples showing the benefits of each would be nice too :)