Set environment variables in Bourne shell (sh)

Contributor Icon Contributed by qmchenry  
Tag Icon Tagged: Bourne shell  


An environment variable must be set and exported with separate commands in the Bourne shell. To set the EDITOR variable to vi, use:

EDITOR=vi
export EDITOR

These commands can be placed in ~/.profile to be executed automatically at login, placed in a shell script, or executed manually. Exporting a variable makes it available to other shells spawned from the current shell as when running another command or shell script.

To add to an existing variable, such as path, use this format:

PATH=$PATH:/usr/local/bin
export PATH EDITOR

Multiple variables can be exported with one export command.

 

3 Comments -


  1. Name said on March 29, 2010

    Not right exactly.
    SH = Bourne Shell
    Bash = Bourne Again Shell
    http://en.wikipedia.org/wiki/Bourne_shell

  2. Anonymous said on May 3, 2010

    Can we do export and set in one command in bash ?

  3. Duncan Anderson said on December 13, 2010

    As far as I know, the commands must be on separate lines in the Bourne shell. I n the Korn shell it is possible to use one line thus:

    EDITOR=vi export EDITOR

    If I am not mistaken this also works in Bash.

 

RSS feed for comments on this post. TrackBack URL

Leave a comment -