What's the difference between set, export and env and when should I use each?

Posted by Oli on Ask Ubuntu See other posts from Ask Ubuntu or by Oli
Published on 2012-10-24T09:34:54Z Indexed on 2012/10/24 11:17 UTC
Read the original article Hit count: 157

Filed under:
|

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 :)

© Ask Ubuntu or respective owner

Related posts about command-line

Related posts about bash