up vote 1 down vote favorite
share [g+] share [fb]

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?

link|improve this question

78% accept rate
see also: superuser.com/questions/176783/… – lesmana May 1 '11 at 12:46
feedback

2 Answers

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
link|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
show 4 more comments
feedback

or you could just execute: export $VARIABLE="stufffff"

link|improve this answer
It does not work from within a shell (tried it now again to be sure). – Adam Matan Aug 9 '09 at 12:41
1  
Drop the $ in the assignment: export VARIABLE="stufffff" – Richard Hoskins Aug 9 '09 at 15:16
But the question is how to do it in a script, so this is all moot. – Richard Hoskins Aug 9 '09 at 15:17
feedback

Your Answer

 
or
required, but never shown

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