Setting environment variables from a file :

Hi,

I have around 10 environment variables in my shell script. i want to set this all in a file and just call that file in my shell script. How can i do that ? Please help. TIA!

Simply enter them in the form

KEY=value

one to a line in the file (called config.sh in this example), then execute the commands in the file in the script

#!/bin/bash
. config.sh
env

Hi,

I tried that approach, it doesnt seem to work.. is there any other way. I am using Korn shell btw.

Yea, similar to above for me.

File called env.vars:

VARIABLE=Value;  EXPORT VARIABLE
VARIABLE2=Value2; EXPORT VARIABLE2
#!/bin/ksh

#Set environment variables.
. env.vars

In what way does it 'not work'? Show exactly what you did, word for word, letter for letter, keystroke for keystroke, because that is the proper method for reading variables from a script.

Note how he does not just run the script. He sources it. . script Dot space, not dot-slash.

Your chances for help would improve if you showed examples of how you are currently trying it and what the output is.

Ah, you are using the Korn shell, therefore you need to provide the full path to the config file (or have it in your PATH). Korn assumes it should search the PATH unless a path is supplied to the shell (odd but true), ie

#!/bin/ksh
. ./config.sh