setting environment (324 Views)
Reply
Frequent Advisor
Salman Ahmed Qureshi
Posts: 68
Registered: ‎01-28-2009
Message 1 of 14 (324 Views)
Accepted Solution

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
Exalted Contributor
Steven E. Protter
Posts: 33,806
Registered: ‎08-15-2002
Message 2 of 14 (324 Views)

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
Honored Contributor
Venkatesh BL
Posts: 1,096
Registered: ‎09-12-2004
Message 3 of 14 (324 Views)

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?!
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 4 of 14 (324 Views)

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...
Frequent Advisor
Salman Ahmed Qureshi
Posts: 68
Registered: ‎01-28-2009
Message 5 of 14 (324 Views)

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
Frequent Advisor
Salman Ahmed Qureshi
Posts: 68
Registered: ‎01-28-2009
Message 6 of 14 (324 Views)

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
Honored Contributor
Venkatesh BL
Posts: 1,096
Registered: ‎09-12-2004
Message 7 of 14 (324 Views)

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 <<
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 8 of 14 (324 Views)

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...

Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 9 of 14 (324 Views)

Re: setting environment

Hi Salman:

My apologies for writing:

YOU=Shalman

...I should have written:

YOU=Salman

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

Regards!

...JRF...
Frequent Advisor
Salman Ahmed Qureshi
Posts: 68
Registered: ‎01-28-2009
Message 10 of 14 (324 Views)

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
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 11 of 14 (324 Views)

Re: setting environment

Hi (again) Salman:

> Thank you very much all. It works same like Linux :)

Yes, indeed, it would work the same as Linux, or rather, Linux would work the same as Unix in the regard :-)

I see that you are new to our community. Welcome. If you are satisfied with the help you received, please read:

http://forums13.itrc.hp.com/service/forums/helptips.do?#28

Regards!

...JRF...
Acclaimed Contributor
Dennis Handly
Posts: 25,274
Registered: ‎03-06-2006
Message 12 of 14 (324 Views)

Re: setting environment

>script name is "env".

This command is reserved and you absolutely should NOT use it.

>What is the problem and how to resolve it?

You are probably invoking /usr/bin/env.

>please make a correction, my name is SALMAN, not Shalom

Steven is giving you (and every reply) a polite well wishing greeting:
http://en.wikipedia.org/wiki/Shalom

>I followed your instructions but problem and error message is same

Of course, since that wasn't your real problem, just a good practice.

Note if you are always going to source this file, you don't need #!/sbin/sh and you shouldn't make the file executable.
Frequent Advisor
Salman Ahmed Qureshi
Posts: 68
Registered: ‎01-28-2009
Message 13 of 14 (324 Views)

Re: setting environment

Hi Dennis

>please make a correction, my name is SALMAN, not Shalom

>Steven is giving you (and every reply) a polite well wishing greeting:
>http://en.wikipedia.org/wiki/Shalom


Oh i am really sorry. I thought he is misspelling my name because it seemd like my own name.
My appologies Mr Steven

Salman
Esteemed Contributor
Arturo Galbiati
Posts: 830
Registered: ‎02-10-2003
Message 14 of 14 (324 Views)

Re: setting environment

Hi Salman,
end is a reserved word, chnage the name of your script to my_env.
HTH,
Art
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.