load variables from file to execute shell script

Hello,

I want to load variables from file to execute shell script.
The goal is not having variables on the script :
export PATH=/usr/bin:/etc:/usr/sbin:/usr/local/bin:/usr/ccs/bin:/usr/ucb:/usr/openwin/bin:/u01/app/oracle/product/10.2.0/bin:/bin:/u01/app/oracle/product/10.2.0:.
export LD_LIBRARY_PATH=/usr/sfw/lib:/usr/local/lib:/u01/app/oracle/product/10.2.0/lib
IMP_LOG=/u02/data/transfer/common/imp/log
IMP_CFG=/u02/data/transfer/common/imp/config
IMP_BIN=/u02/data/transfer/common/imp/bin
DATA_DUMR_DIR=/u02/data/transfer/appli
LOGFILE=${IMP_LOG}/impfull_pipe_${ORACLE_SID}_${IMPDATE}
IMPDATE=$(date +%d%m%y_%H%M%S)
#DAY=`TZ=CST+22 date +%Y%m%d`
DAY=`date +%Y%m%d`
ENVIRONMENT=_PRP
TOENVIRONMENT=_PRP
EXE_PW=/u02/data/transfer/common/oraenv/config/utab

How can I do it?

Thanks

Regards
bibi92Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

woolmilkporcCommented:
Just add near the top of your script:

. /path/to/file_containing_variables

Note: the dot "." must be followed by a space!

Alternatively (bash):

source /path/to/file_containing_variables
0
bibi92Author Commented:
ok is it possible not add the name of the file file_containing_variables on the script but in parameter for executing the script :

./load_data.ksh file_containing_variables

Thanks

Regards
0
woolmilkporcCommented:
Yes, that's possible.

Near the top of "load_data.ksh" add:

. $1

or, for better readability:

VARFILE=$1
. $VARFILE
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

bibi92Author Commented:
Is it possible to add on the top of load_data.ksh ?
/path/to/. $1

Thanks

Regards
0
woolmilkporcCommented:
Sorry, but it isn't possible. The dot must appear first, because it is (kind of) a command.

"." or "source" means: Execute the specified file inside the current shell instead of spawning a subshell.
This is required because variables set in a subshell do ot become known to the callings shell or, in other words, a subshell cannot mosify the parent shell's environment.

So this is the correct way:

. /path/to/$1
0
bibi92Author Commented:
The file envtarget contains _PRP

$ -> ENVIRONMENT=/transfer/common/imp/config/envtarget

$ -> VARENV=$ENVIRONMENT
If  I execute . $VARENV
$ -> . $VARENV
-bash: _PRP: command not found

How can I resolve it, please ?

Thanks
0
ozoCommented:
In what context does the file envtarget contain _PRP ?
ENVIRONMENT=_PRP
TOENVIRONMENT=_PRP
should not cause that error

unless you then try to execute
$ -> $ENVIRONMENT
0
woolmilkporcCommented:
How did you create envtarget ? Or where does it come from?
0
bibi92Author Commented:
I've requested that this question be deleted for the following reason:

Hello, I have found the solution :
EXE_ENVIRONMENT=/u02/data/transfer/common/imp/config/envsource
EXE_TOENVIRONMENT=/u02/data/transfer/common/imp/config/envtarget
ENVIRONMENT=`cat $EXE_ENVIRONMENT`
TOENVIRONMENT=`cat $EXE_TOENVIRONMENT`
0
woolmilkporcCommented:
The "solution" posted by the asker is in no way related to the original question.
My suggestions, on the other hand, provide valid solutions.
0
bibi92Author Commented:
my question was I want to load variables from file to execute shell script. The goal is not having variables on the script .
So I create the files envsource and envtarget
EXE_ENVIRONMENT=/u02/data/transfer/common/imp/config/envsource
EXE_TOENVIRONMENT=/u02/data/transfer/common/imp/config/envtarget
envsource contains _PRP
envtarget contains _PRP
I load the files with following commands :
ENVIRONMENT=`cat $EXE_ENVIRONMENT`
TOENVIRONMENT=`cat $EXE_TOENVIRONMENT`

Thanks

Regards
0
woolmilkporcCommented:
>> I want to load variables from file to execute shell script. <<

That's exactly what "." or "source" do. If your "files" contain invalid data - don't blame me!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.