943,598 Members | Top Members by Rank

Ad:
Feb 19th, 2004
0

Problem with variables in Windows shell script

Expand Post »
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!
Similar Threads
Jem
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Jem is offline Offline
1 posts
since Feb 2004
Feb 2nd, 2005
0

Re: Problem with variables in Windows shell script

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.

Quote originally posted by Jem ...
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!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ronen.fishman is offline Offline
1 posts
since Feb 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Windows NT / 2000 / XP Forum Timeline: Changing Language setting
Next Thread in Windows NT / 2000 / XP Forum Timeline: cdrw burning





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC