General
cancel
Showing results for 
Search instead for 
Did you mean: 

environment variable is not set when executing script..

Friend_2
Occasional Visitor

environment variable is not set when executing script..

Hi,

i am executing script .script executed successfully. but environment variable is not set...

Sript:
sid1.sh

code:

output:

[oracle@test1 shell]$ sh sid1.ksh

********************************************************************************
The current ORACLE_SID value is testdb
********************************************************************************
The following are valid instance names along with the ORACLE_HOME value:

1 : bingo
2 : +ASM
3 : star

********************************************************************************

Do you want to change ORACLE_SID [Y/N]? \c
y
Enter Slno of the SID from above list : \c
2
Oracle SID: +ASM
[oracle@test1 shell]$ echo $ORACLE_SID
testdb

2 REPLIES
Goran Koruga
Honored Contributor

Re: environment variable is not set when executing script..

Hello.

Source the script if you want to do this:

source sid1.ksh

(using ". sid1.ksh" has the same effect).

Regards,
Goran
Steven Schweda
Honored Contributor

Re: environment variable is not set when executing script..

> [...] environment variable is not set...

Actually, the environment variables _were_
set, but they were set in the wrong process.

> [oracle@test1 shell]$ sh sid1.ksh
> [...]

This runs a shell ("sh"), which runs the
shell script, which runs its own shell
("#!/bin/ksh"), and that "/bin/ksh" process
is where the environment variables were set.
When that process exits, its environment
(with the desired changes) disappears.

> [...] ". sid1.ksh" [...]

That causes the current shell to read the
commands in the file, so that when those
commands set environment variables, the
variables are set in the current shell's
environment, not in some (transient)
sub-shell's environment.

> #!/bin/ksh

A line like this serves no purpose here,
because this is not a complete shell script
-- the current shell must always read
("source") the file (". file"). (Thus, you
couldn't use the same file with a C shell.)