I am at a bit of a loss as to the purpose of set
and export
in Bash (and I guess probably other shells too).
I would think it is for setting environment variables, but that can be done just with VARIABLE=VALUE
, right?
Also typing set
and export
on their own show different values.
So what is their purpose?
Best Answer
export
exports to children of the current process, by default they are not exported. For example:set
, on the other hand, sets shell attributes, for example, the positional parameters.Note that
baz
is not assigned tofoo
, it simply becomes a literal positional parameter. There are many other thingsset
can do (mostly shell options), seehelp set
.As for printing,
export
called with no arguments prints all of the variables in the shell's environment.set
also prints variables that are not exported. It can also export some other objects (although you should note that this is not portable), seehelp export
.