| | |
Problem with variables in Windows shell script
![]() |
•
•
Join Date: Feb 2004
Posts: 1
Reputation:
Solved Threads: 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!
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!
•
•
Join Date: Feb 2005
Posts: 1
Reputation:
Solved Threads: 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.
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.
•
•
•
•
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!
![]() |
Similar Threads
- Objective C launching NSTask to run a shell script and get output (C)
- problem running mysql shell script (Shell Scripting)
- Invoking a shell script (PHP)
- Windows DOS Shell Script Help (IT Professionals' Lounge)
- problem with variable expansion in shell script (Shell Scripting)
- Convert shell script for looping (Shell Scripting)
- c++ or shell script to delete some files (C++)
Other Threads in the Windows NT / 2000 / XP Forum
- Previous Thread: Changing Language setting
- Next Thread: cdrw burning
| Thread Tools | Search this Thread |
.net 64bit 2007 2010 a.exe address apache appstore arm auto black blue book bsod bulletin canonical cellphones codeplex computer crash cursor deployment deployments desktop desktops dns dotnetnuke drive eartlink error errors explorer fax features folder fontmanagers format framework freeze hardware home intel interoperability killprocess laptop linux load login mac memory microsoft monitor motionle1600 netbooks novell nvidia operatingsystems options osx palm patch printer product program reformat remotedesktop repair replacingraiddrive retail retrieve screen security sharepoint simplifiedchinese sitetositevpn slowperformance technology unreadable update usb verizon videodrivers videogames virus vista visual vpn vulnerability wab webos weecam win win32/heur windows windows7 windowsxp windowsxpnotstartingup. worm xp xpde





