Using The export Shell Command

One of the most commonly used but not well understood by everyone is the export shell command. The way most of the users know about it is through installation instructions of many softwares which require environment variables to be set.

The command export TERM=xterm means that the environment variable TERM is available to any other program, or more suitably, any process that is started from that shell after the variable is set. So, if I start another script from my shell, then I will get the value xterm when I check the variable TERM. If you set it in your .bashrc then it is available all processes that are started from that shell.

If you don’t want to make the variable to these processes, then you can use TERM=xterm. That will limit its scope to that specific shell.

Not understanding export can cause problems. Apart from the necessity of exporting some variables for some programs to work properly, exporting some others might have side-effects. For example, exporting the CDPATH variable might cause some scripts to unpredicted behaviour from programs which assume that the directory base has not been reset. Export only those variables which will be needed by others, and leave the others within your shell.

Discussion [Participate or Link]

  1. Maxim said:

    Good one …

Say your thought!

If you want to use HTML you can use these tags: <a>, <em>, <strong>, <abbr>, <code>, <blockquote>. Closing the tags will be appreciated as this site uses valid XHTML.



Abhijit Nadgouda
iface Consulting
+91 9819820312
My bookmarks


This is the weblog of Abhijit Nadgouda where he writes down his thoughts on software development and related topics. You are invited to subscribe to the feed to stay updated or check out more subscription options. Or you can choose to browse by one of the topics.