Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
Other versions of this page are also available for the following:
Windows Mobile Not Supported Windows Embedded CE Supported
8/28/2008

This command evaluates an expression and conditionally executes a set of script commands.

The if  booleancommand does a Boolean comparison.

The if  datetimecommand does a date comparison.

The if  numbercommand does a numeric comparison.

The if  stringcommand does a case-sensitive string comparison. The containsoperator is used to see if a given string contains a particular substring, in a manner similar to the C language strstrfunction.

The if  versioncommand does a comparison between two version strings.

Syntax


if boolean [
boolean string
]
[ == | != ] [
boolean string
]
if datetime [
datetime string
]
[ == | != | < | <= | > | >=] [
datetime string
]
if number [
numeric string
]
[ == | != | < | <= | > | >=] [
numeric string
]
if string [
string
]
[ == | != | < | <= | > | >= | contains] [
string
]
if version [
version string
]
[ == | != | < | <= | > | >=] [
version string

]

Parameters

boolean string

The Boolean strings can be either TRUE, ON, YES, or 1 to represent a logical 1 or they can be either FALSE, OFF, NO, or 0 to represent a logical 0.

datetime string

The datetime string represents a particular date and time and is specified as <4 digit year>-<month number>-<month day> <hours>:<minutes>:<seconds>. The right-hand side datetime stringcan also be one of the following special keywords:

yesterday

lastmonth

today

thismonth

tomorrow

nextmonth

lastweek

lastyear

thisweek

thisyear

nextweek

nextyear

These keywords can be used instead of specific dates to make scripts operative on relative time values.

numeric string

Each of the two numeric stringspecifies the numbers you want to do a numeric comparison on.

string

Each of the two stringspecifies the strings you want to do a case-sensitive string comparison on.

version string

Each of the two version stringspecifies the versions you want to do a version comparison on.

Remarks

You can specify multiple expressions to evaluate on a single command line using the ORoperator between the expressions.

The following code example uses the ifcommand to decide which message to output:

Copy Code
if string "%CCA_CURRENTLANGUAGE%" == "en-US"
  echo "Hello World"
elseif string "%CCA_CURRENTLANGUAGE%" == "fr-CA"
  echo "Bonjour le Monde"
else
  echo "Hello"
endif

The following code example shows how to use the ORoperator to specify multiple expressions on one command-line:

Copy Code
if string "%CCA_DEFAULTSTORE%" == dsk1: OR boolean "`pkginstalled
MyPackage`" == TRUE
  echo "Hello World"
endif

See Also