I have noticed in my .bashrc
that some lines have export
in front of them, such as
export HISTTIMEFORMAT="%b-%d %H:%M "
...
export MYSQL_HISTFILE="/root/.mysql_history"
whereas others don't, such as
HISTSIZE=100000
I am wondering if, first, this is correct, and second what the rule is for using export
in .bashrc
.
Best Answer
You only need
export
for variables that should be "seen" by other programs which you launch in the shell, while the ones that are only used inside the shell itself don't need to beexport
ed.This is what the man page says:
This can be demonstrated with the following:
Explanation:
${MYVAR}
to be a Shell variable withMYVAR="value"
. Usingecho
I can echo the value of it because echo is part of the shell.echo.sh
. That's a little script that basically does the same, it just echoes${MYVAR}
, but the difference is that it will run in a different process because it's a separate script.echo.sh
it outputs nothing, because the new process does not inherit${MYVAR}
${MYVAR}
into my environment with theexport
keywordecho.sh
again, it echoes the content of${MYVAR}
because it gets it from the environmentSo to answer your question:
It depends where a variable is going to be used, whether you have to export it or not.