Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
cancel
Showing results for 
Search instead for 
Did you mean: 

setting environment

SOLVED
Go to solution
Highlighted
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
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
James R. Ferguson
Acclaimed Contributor

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...
Dennis Handly
Acclaimed Contributor

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.
Salman Ahmed Qureshi
Frequent Advisor

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
Arturo Galbiati
Esteemed Contributor

Re: setting environment

Hi Salman,
end is a reserved word, chnage the name of your script to my_env.
HTH,
Art