0

Hi!

I'm trying to setup a shell script to startup a number of programs when I run it, but I've got some issues with variables that is causing it not to work...

The bunch of lines at fault is this:

if /I "%INST%" == "OID" (
set NAME=9iAS_INF
set HOME=D:\oracle\%NAME%
rem set PATH=%HOME%\bin;%HOME%\dcm\bin;%HOME%\opmn\bin;%PATH%
set ORACLE_HOME=%HOME%
goto END
set ORACLE_SID=iasdb
GOTO OID
)

Now... %INST% has been previously set as %1, and that seems to work fine. However, sometimes the HOME and ORACLE_HOME variables don't work! (I've got the 'goto END' in there so the script doesn't actually execute.) I've added setlocal to the start of the script and endlocal to the end, as well.

Here's the output (I set echo to on):

C:\Documents and Settings\jhiggs>if /I "oid" == "OID" (
set NAME=9iAS_INF
set HOME=D:\oracle\
rem set PATH=\bin;\dcm\bin;\opmn\bin;D:\oracle\OWB_S\bin;D:\oracle\OWB_DT\bin;D
:\oracle\9iAS_INF\bin;C:\oracle\9iDS\jdk\jre\bin\classic;C:\oracle\9iDS\jdk\jre\
bin;C:\oracle\9iDS\bin;C:\oracle\9iDS\jlib;D:\oracle\9iAS_BI\jdk\jre\bin\classic
;D:\oracle\9iAS_BI\jdk\jre\bin;D:\oracle\9iAS_BI\bin;D:\oracle\9iAS_BI\jlib;D:\o
racle\9iAS_INF\jlib;D:\oracle\9iDB\bin;C:\Program Files\Oracle\jre\1.3.1\bin;C:\
Program Files\Oracle\jre\1.1.8\bin;C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\
Wbem;C:\Program Files\Symantec\pcAnywhere\;D:\script\;D:\oracle\9iAS_INF\bin\;D:
\oracle\9iAS_BI\bin\
set ORACLE_HOME=
goto END
set ORACLE_SID=iasdb
GOTO OID
)

C:\Documents and Settings\jhiggs>endlocal

So in this case, NAME is correct, but HOME has not been set for some reason, as it's D:\oracle ... as a result, ORACLE_HOME is not set either, which causes the program to not start correctly later in the script!

Can anyone help? I'm new to shell scripting in Windows (I've done BASH shell scripting, but not Windows) I think it's got something to do with the NAME and HOME variables, but I'm not sure what...

Thanks a lot!

2
Contributors
1
Reply
2
Views
13 Years
Discussion Span
Last Post by ronen.fishman
0

Hi,

The problem with what you did is that all the if body is infact a single command, so the shell first substitutes the variables and only then execute the command.

One simple way to overcome this is to include a single goto command in the if body to a place where you'll do the setting commans one by one.

An even simpler way is to use cmd /v and !NAME! rather then %NAME%

You can read more by typing "help set" on a cmd (at least on xp professional).

Regards,
Ronen.

Hi!

I'm trying to setup a shell script to startup a number of programs when I run it, but I've got some issues with variables that is causing it not to work...

The bunch of lines at fault is this:

if /I "%INST%" == "OID" (
set NAME=9iAS_INF
set HOME=D:\oracle\%NAME%
rem set PATH=%HOME%\bin;%HOME%\dcm\bin;%HOME%\opmn\bin;%PATH%
set ORACLE_HOME=%HOME%
goto END
set ORACLE_SID=iasdb
GOTO OID
)

Now... %INST% has been previously set as %1, and that seems to work fine. However, sometimes the HOME and ORACLE_HOME variables don't work! (I've got the 'goto END' in there so the script doesn't actually execute.) I've added setlocal to the start of the script and endlocal to the end, as well.

Here's the output (I set echo to on):

C:\Documents and Settings\jhiggs>if /I "oid" == "OID" (
set NAME=9iAS_INF
set HOME=D:\oracle\
rem set PATH=\bin;\dcm\bin;\opmn\bin;D:\oracle\OWB_S\bin;D:\oracle\OWB_DT\bin;D
:\oracle\9iAS_INF\bin;C:\oracle\9iDS\jdk\jre\bin\classic;C:\oracle\9iDS\jdk\jre\
bin;C:\oracle\9iDS\bin;C:\oracle\9iDS\jlib;D:\oracle\9iAS_BI\jdk\jre\bin\classic
;D:\oracle\9iAS_BI\jdk\jre\bin;D:\oracle\9iAS_BI\bin;D:\oracle\9iAS_BI\jlib;D:\o
racle\9iAS_INF\jlib;D:\oracle\9iDB\bin;C:\Program Files\Oracle\jre\1.3.1\bin;C:\
Program Files\Oracle\jre\1.1.8\bin;C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\
Wbem;C:\Program Files\Symantec\pcAnywhere\;D:\script\;D:\oracle\9iAS_INF\bin\;D:
\oracle\9iAS_BI\bin\
set ORACLE_HOME=
goto END
set ORACLE_SID=iasdb
GOTO OID
)

C:\Documents and Settings\jhiggs>endlocal

So in this case, NAME is correct, but HOME has not been set for some reason, as it's D:\oracle ... as a result, ORACLE_HOME is not set either, which causes the program to not start correctly later in the script!

Can anyone help? I'm new to shell scripting in Windows (I've done BASH shell scripting, but not Windows) I think it's got something to do with the NAME and HOME variables, but I'm not sure what...

Thanks a lot!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.