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
  • 42,186
  • 14
  • 105
  • 129
Adam Matan
  • 8,090
  • 17
  • 59
  • 84
  • see also: http://superuser.com/questions/176783/what-is-the-difference-between-executing-a-bash-script-and-sourcing-a-bash-script/176788#176788 – Lesmana May 01 '11 at 12:46

2 Answers2

5

file export_FOOBAR:

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

at the prompt

yourhost:/~ > source export_FOOBAR
lexu
  • 1,872
  • 7
  • 27
  • 41
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
  • 24,736
  • 27
  • 129
  • 199