Set Environment variable from another file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Set Environment variable from another file
# 1  
Old 09-02-2010
Set Environment variable from another file

Hi,

i have the following env variable. currently i am exporting variable in the same script file. but i need this is in a text file and the scripts need to export this variable from the text file.

can you please suggest me. is it possible.

Code:
export INFA_SHARED=${INFA_HOME}/server/infa_shared
export PMCMD=${INFA_HOME}/server/bin/pmcmd
export PMSERVERPORT=6001
export PMSERVERNAME=$HOSTNAME
export PMUSERNAME=Administrator
export PMPASSWORD=Administrator
export DOMAIN_NAME=Domain_rcirs111


Last edited by pludi; 09-02-2010 at 03:55 AM.. Reason: code tags, please...
# 2  
Old 09-02-2010
Hi,

If I understand you correctly, you want a sort of "config" file which is read by your script, and the directives/variables inside the "config" file are to be exported to the current context in which the script is running?

If so, then as long as you have your current shell-parseable tokens in the config file, it should be a matter of "source"ing the config file

Code:
. config_file

or
Code:
source config_file

where config_file would contain:

Code:
MYVAR=foo
BARVAR=baz

HTH

Last edited by dsw; 09-02-2010 at 04:23 AM.. Reason: typos galore
# 3  
Old 09-02-2010
how to create config_file.

vi mode is acceptable for crating config file.

like....vi config_file
# 4  
Old 09-02-2010
Edit it in any way you choose - vi will work, yes.

The name of the file is irrelevant - it's just to give you an idea about "." and "source".

dan.
# 5  
Old 09-02-2010
for example

vi sorce.conf
vi config
vi config_file
vi config_files

can you please confirm me whch one is right one.
# 6  
Old 09-02-2010
You can call the file anything you like. The filename itself is not relevant here. How you export the environment variable is, of which I have explained in my initial reply.
# 7  
Old 09-03-2010
Hi thanks

but my main question is.

my export varible has password and username
like

export PMUSERNAME=Administrator
export PMPASSWORD=Administrator
export DOMAIN_NAME=Domain_rcirs111

this can be showing all users....but i need "Administrator" "Domain_rcirs111
" should be in some another file and it can be pass to PMUSERNAME,PMPASSWORD and DOMAIN_NAME.

i have tried like the below

cred.txt
-------------
Administrator
Administrator
Domain_rcirs111


sample.sh
-------------
export PMUSERNAME=`head -1 creditional.txt|tail -1`
export PMPASSWORD=`head -1 creditional.txt|tail -1`
export DOMAIN_NAME=`head -1 creditional.txt|tail -1`

but this is not exporting properly...

---------- Post updated at 11:31 PM ---------- Previous update was at 08:47 AM ----------

please help me on the above
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

How to search for the sessions that have a certain environment variable set?

Hi all, In Solaris 10, is there a way to search for the sessions that have a certain environment variable set? (8 Replies)
Discussion started by: ejianu
8 Replies

2. Shell Programming and Scripting

Resolving the environment variable from a file

Hi, I an having some environment variables exported and the variable name is present in the file. But its not resolving with following commands. Can someone throw some light. db $ grep -v "^#" TD_FWK_NUCLEUS.dbc | grep -v "^$" | xargs -i echo {} wb_bin: ${TD_FWK_NUCLEUS_DBC_WB_BIN_TAG} I... (3 Replies)
Discussion started by: Mohammed Rafi
3 Replies

3. Shell Programming and Scripting

Setting Environment variable from value in file

I've searched Google and now this forum. Best guess is my search fu is not good (and it probably isn't). The Google search did bring me here. Background I have a number of Korn Shell scripts who all use one of 3 values for an environment variable used in the backup system. On occasion one or... (8 Replies)
Discussion started by: WolfBrother
8 Replies

4. UNIX for Dummies Questions & Answers

ORACLE_HOME environment variable not set!

hi, i am new to perl: os : Linux i wrote simple perl script to select from table i am getting this error and how to set ORACLE_HOME environment variable : script: #!usr/bin/perl use DBI; use Mail::Sendmail; #use Date::Calc; use MIME::QuotedPrint; use HTML::Entities; use POSIX... (2 Replies)
Discussion started by: prakash.gr
2 Replies

5. Solaris

set environment variable?

I am working with solaris 9 sunBlade150 Box. I Installed a program, need to set the environment variable so that when the executable is entered,it finds the path to the executable. The documentation for the software says: Set the appropriate environment variable: Connect to server failed;... (8 Replies)
Discussion started by: smartgupta
8 Replies

6. Linux

How do i set environment variable

Hi, I am quite new to Linux. And I have doubt how to set new environment variable with value to a C executable. Let say I have a environment variable $Hack ; I would like to load a value for this variable; so that when the C executable is executed, the $Hack would set the variable value. ... (4 Replies)
Discussion started by: ahjiefreak
4 Replies

7. Shell Programming and Scripting

problem in getting the path of environment variable set in bashrc in my shell script

hi all i have joined new to the group. i have set an variable in my bashrc file. .bashrc PROGHOME=/home/braf/braf/prog export PROGHOME but while using it in my shell script its path is not taken and i had to explicitly give the export command to set the path. in my script... (8 Replies)
Discussion started by: krithika
8 Replies

8. UNIX for Advanced & Expert Users

how to set the environment variable at run time

hi, I have one environment variable like path in my system.But in my program i need to change that path .suppose it has a value "config" now i need to chage it as "config1" or something else.i need to use that variable for complete project.It means at first it will use the old path but after... (4 Replies)
Discussion started by: sada@123
4 Replies

9. UNIX for Advanced & Expert Users

set environment variable?

Installed a program, need to set the system up so that when the executable is entered, it finds the path to the executable. In Windows, set under system properties, advanced, environmental variables. How do I do this with Unix? Specifically using Solaris 9. I have tried: env... (3 Replies)
Discussion started by: kohoutek
3 Replies

10. UNIX for Advanced & Expert Users

How does the PATH and MANPATH environment variable get set?

Hi, How does the PATH and MANPATH environment variable get set? I want to add "/opt/SUNWspro/bin" to the search path for all the users. Where can I access this variable. I know in my home directory, depend on which shell I use, there are files such as .profile and .cshrc which I can edit to... (3 Replies)
Discussion started by: vtran4270
3 Replies
Login or Register to Ask a Question