1

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?

quack quixote
  • 43,504
Adam Matan
  • 8,740

2 Answers2

5

file export_FOOBAR:

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

at the prompt

yourhost:/~ > source export_FOOBAR
lexu
  • 1,892
1

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
kenorb
  • 26,615