Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to set environment variables from within a (bash) shell script?

I want to set some environment variables on some servers using a small script rather than typing. Some forum posts believe it is impossible.

Any Ideas?

share|improve this question
see also:… – lesmana May 1 '11 at 12:46
up vote 5 down vote accepted

file export_FOOBAR:

# set variable FOOBAR to "hi"
export FOOBAR

at the prompt

yourhost:/~ > source export_FOOBAR
share|improve this answer
Great. What dose 'source' mean? – Adam Matan Aug 9 '09 at 12:13
type "man source" in your shell – Nifle Aug 9 '09 at 12:45
type "man <any_shell_command>" to find out what it does – Nifle Aug 9 '09 at 12:47
I have none. It's probably part of bash - where can I find its docs? – Adam Matan Aug 9 '09 at 12:48
Good, but I wouldn't put #!/bin/bash (I assume that's what you meant) at the start of the script, as this script won't work if executed. – Douglas Leeder Aug 9 '09 at 13:23

For Bash built-ins, use the built-in help. E.g.:

$ help source

To see if a command will be handled by the shell (is a built-in), use the type bash built-in:

$ type help

$ type type
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.