1753263 Members
4973 Online
108792 Solutions
New Discussion юеВ

Re: setting environment

 
SOLVED
Go to solution
Salman Ahmed Qureshi
Frequent Advisor

setting environment

Hi,
i have written a script with following contents and script name is "env". I actualy want my environment to be set when i execut his script.

#!/sbin/sh
export ORACLE_BASE=/oracle
expoer ORACLE_HOME=$ORACL_BASE/product/bin

on prompt, i execute ". env", it returns me error mesage

su:Syntex error: '(' is not expected.

What is the problem an how to resolve it?
Thanks

Salman
13 REPLIES 13
Steven E. Protter
Exalted Contributor

Re: setting environment

Shalom,

double quote your long strings. ORACLE_HOME

Change"
export ORACLE_HOME=$ORACL_BASE/product/bin

to:

export ORACLE_HOME="${ORACL_BASE}/product/bin"

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Venkatesh BL
Honored Contributor

Re: setting environment

It works for me without any change...

# export ORACLE_BASE=/oracle
# export ORACLE_HOME=$ORACLE_BASE/product/bin

# echo $ORACLE_BASE
/oracle
# echo $ORACLE_HOME
/oracle/product/bin

# echo $SHELL
/sbin/sh

Are you sure you typed correctly?!
James R. Ferguson
Acclaimed Contributor

Re: setting environment

Hi:

You do:

# . env
sh: Syntax error: `(' is not expected.

No, you want,simply:

# env

You can redirect the output into a file:

# env > myenv

...or capture it in a variable to parse later:

# MYENV=$(env)
# echo ${MYENV}
...

If you preceed the above with:

# export ORACLE_BASE-/oracle

...then you will see that too when you query your current environment.

Regards!

...JRF...
Regards!

...JRF...
Salman Ahmed Qureshi
Frequent Advisor

Re: setting environment

Hello Steven, please make a corection, my name is SALMAN, not Shalom
I folowed your instructions but problem and error message is same

Venkatesh, if i write it on shell prompt, it works fine, but i want to write a script file so that when i execute it in my shell, it set all envirnoments.
Thanks

Salman
Salman Ahmed Qureshi
Frequent Advisor

Re: setting environment

Mr JAmes,
Thanks for your reply. i am a bit new in HP Unix, the thing i am doing works fine with Linux. I didn't get what you what ou want me to do.
I simpley want to set 4 environment variabes to be set when i execute a script file. I would appreciate if you could tell me how to do this in a simple way.
I would need a few diffirent scripts files to set my environment for different versions of oracle.
Thanks

Salman
Venkatesh BL
Honored Contributor
Solution

Re: setting environment

1) put the following in a file (say 'env'):
#!/sbin/sh
export ORACLE_BASE=/oracle/aaa
export ORACLE_HOME=${ORACLE_BASE}/product/bin

2) # chmod +x ./env ;; make it executable.

3) . ./env ;; source the file.

4) # echo $ORACLE_BASE
/oracle <<
James R. Ferguson
Acclaimed Contributor

Re: setting environment

Hi (again) Salman:

You wrote:

#!/sbin/sh
export ORACLE_BASE=/oracle
expoer ORACLE_HOME=$ORACL_BASE/product/bin

on prompt, i execute ". env", it returns me error mesage

As I said, to declare and export variables into your environment do:

#!/sbin/sh
export ORACLE_BASE=/oracle

...That is correct and you can see this in your current environment with:

# env

...Notice that you don't issue '. env' only 'env' at the prompt.

NOW, if you want one shell script to pass environmental variables into another shell script, do this:

# cat myenv
#!/usr/bin/sh
YOU=Shalman
ME=JRF
WHERE="at work"

...This declares variables you want to pass around in your environment.

# cat myscript
#!/usr/bin/sh
. ./myenv
echo "I am ${ME} and you are ${YOU} and we are ${WHERE}"

...Notice the dot-space-filename used to source (or read) the file './myenv'. This means that the shell (your script, 'myscript' doesn't run './myenv' but rather reads it into your _current_ environment. Now, when you excute:

# ./myscript
I am JRF and you are Shalman and we are at work

...is displayed.

Regards!

...JRF...

James R. Ferguson
Acclaimed Contributor

Re: setting environment

Hi Salman:

My apologies for writing:

YOU=Shalman

...I should have written:

YOU=Salman

...in the 'myenv' variables :-)

Regards!

...JRF...
Salman Ahmed Qureshi
Frequent Advisor

Re: setting environment

Hi,
Thank you very much all.
It works same like Linux :)
Only mistake i was making was to name my script "env". I have changed its name to "abc" and it is working fine
Thanks any way

Salman