Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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: superuser.com/questions/176783/… – lesmana May 1 '11 at 12:46
up vote 5 down vote accepted

file export_FOOBAR:

# set variable FOOBAR to "hi"
FOOBAR=hi
export FOOBAR

at the prompt

yourhost:/~ > source export_FOOBAR
share|improve this answer
1  
Great. What dose 'source' mean? – Adam Matan Aug 9 '09 at 12:13
1  
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
1  
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .