Specifications

144 Version 2.0
Examples
#
# Example script for “if” command usages 1 and 2
#
if exist fs0:\myscript.nsh then
myscript myarg1 myarg2
endif
if %myvar% == runboth then
myscript1
myscript2
else
echo ^%myvar^% != runboth
endif
In this example, if the script file myscript.nsh exists in fs0:\, this script will be
launched with 2 arguments, myarg1 and myarg2. After that, environment variable
%myvar% is checked to see if its value is runboth, if so, script myscript1 and
myscript2 will be executed one after the other, otherwise a message %myvar% !=
runboth is printed.
#
# Example script for “if” command usage 3
#
:Redo
echo Enter 0-6 or q to quit
# assumes “input y” stores a character of user input into variable y
InputCh MyVar
if x%MyVar% eq x then
echo Empty line. Try again
goto Redo
endif
if IsInt(%MyVar%) and %MyVar% le 6 then
myscript1 %MyVar%
goto Redo
endif
if /i %MyVar% ne q then
echo Invalid input
goto Redo
endif
In this example, the script requests user input and uses the if command for input
validation. It checks for empty line first and then range checks the input. Note also
the use of the /i in the last comparison so “Q” and “q” are both supported.
Note: This command does not change the value of the environment variable
lasterror.
Note: The if command is only available in scripts.
Note: The else command is optional in an if/else statement.