Need to SET Environment variables

Hi

Could you please tell me how to set environment variables in Unix ksh.
And how can acess those varibles in shell scripts
( Please give the code with an example)

For my scenario.

We have written number of shell scripts with hard coded username and password.

But if we want to change the password we need to modify in all scripts that is BAD.

We found that by setting environment variable and using those environment varables in shell script would be good(Even changing password in future).

Appriciate you early response.

Thanks,
Shyam.

create a config file with something below

username=abc
password=xyz
....
....
...
servername=efg

save the file as important.config

In your shell script add the below line

. /filepath/important.config

after that you can access the value "abc" using the $username variable.

 
$cat imp.config
username=abc
password=xyz
 
$cat test.sh
#!/bin/ksh
. imp.config
echo $username
echo $password
 
$./test.sh 
abc
xyz

search what is dot character in this forum or just search for source command for more information.

1 Like