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?
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?
5
file export_FOOBAR:
# set variable FOOBAR to "hi"
FOOBAR=hi
export FOOBAR
at the prompt
yourhost:/~ > source export_FOOBAR
BTW: If "man <command>" does not work, b/c the command is built into bash ,you can use "help <command>" . That invokes bash's internal help :-). – sleske – 2010-02-11T22:53:43.987
1Great. What dose 'source' mean? – Adam Matan – 2009-08-09T12:13:13.330
2type "man source" in your shell – Nifle – 2009-08-09T12:45:48.590
type "man <any_shell_command>" to find out what it does – Nifle – 2009-08-09T12:47:50.903
I have none. It's probably part of bash - where can I find its docs? – Adam Matan – 2009-08-09T12:48:35.647
type man bash and then look for the source command (within the bash man page search for 'SHELL BUILTIN COMMANDS' and it is usually shortly after that) – mas – 2009-08-09T12:57:36.387
Bash Reference Manual: http://www.gnu.org/software/bash/manual/bashref.html (your really need to learn about google :-)
– lexu – 2009-08-09T13:20:45.0331Good, 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 – 2009-08-09T13:23:29.760
@Douglas Leeder : working from memory => errors, thx for the feedback – lexu – 2009-08-09T13:27:22.817
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
see also: http://superuser.com/questions/176783/what-is-the-difference-between-executing-a-bash-script-and-sourcing-a-bash-script/176788#176788
– lesmana – 2011-05-01T12:46:08.587