|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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! |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Simply enter them in the form Code:
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 Code:
#!/bin/bash . config.sh env |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
setting environment variables from file
Hi,
I tried that approach, it doesnt seem to work.. is there any other way. I am using Korn shell btw. |
|
#4
|
|||
|
|||
|
Yea, similar to above for me. File called env.vars: Code:
VARIABLE=Value; EXPORT VARIABLE VARIABLE2=Value2; EXPORT VARIABLE2 Code:
#!/bin/ksh #Set environment variables. . env.vars |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
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. |
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
Your chances for help would improve if you showed examples of how you are currently trying it and what the output is.
|
| Sponsored Links | |
|
|
#7
|
||||
|
||||
|
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 Code:
#!/bin/ksh . ./config.sh Last edited by Skrynesaver; 12-05-2012 at 11:09 AM.. Reason: added example for clarity |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Setting environment variables in Cron file | shyamu544 | Shell Programming and Scripting | 4 | 07-20-2011 04:43 AM |
| Setting up environment variables | exchequer598 | UNIX for Dummies Questions & Answers | 2 | 09-03-2010 12:10 AM |
| Setting Environment Variables | bigubosu | UNIX for Dummies Questions & Answers | 4 | 04-30-2010 06:23 AM |
| Need help with setting up environment variables | SSSB | UNIX for Dummies Questions & Answers | 1 | 01-21-2010 02:44 PM |
| Setting up Environment Variables | rpandey | Shell Programming and Scripting | 6 | 06-06-2005 09:28 AM |
|
|