![]() |
Reference Manual |
NAME
if - conditional command executionSYNOPSIS
if [not] [file name] | [variable | constant] [then] cmd [args]+DESCRIPTION
Command if executes the specified command with its arguments if a specified condition is true (non-zero).NOTESEvaluation of the condition proceeds as follows:
- If file is specified, the condition is true if the file named name exists.
- Alternatively, if a variable is specified, the condition is true if the variable is true.
Any settings variable can be evaluated, but the ifn variable (current interface number) deserves special mention because it has a set of property suffixes that can be evaluated instead of the variable itself:
ifn.p True if ifn is the primary interface ifn.s True if ifn is the secondary interface ifn.a True if ifn is the auxiliary interface ifn.v True if ifn is the virtual WiFi interface ifn.f True if ifn is the WiFi interface ifn.w True if ifn is the best Windows interface ifn.r True if ifn is the RAS Server interface ifn.wifi True if ifn is a WiFi interface ifn.vwifi True if ifn is a virtual WiFi interface ifn.vwifi2 True if ifn is a second virtual WiFi interface ifn.main True if ifn is a main Internet interface ifn.internet True if ifn is an Internet interface ifn.private True if ifn is a private interface ifn.aux True if ifn is an auxiliary Internet interface ifn.vpn True if ifn is a VPN interface ifn.pppoe True if ifn is a PPPoE interface ifn.gateway True if ifn has a gateway address ifn.ip True if ifn has an IP address The above suffixes can also be specified as ifn=suffix, in which case true is returned if the numeric value of ifn equals the numeric value of the suffix.
The current interface number ifn can be set with an ip ifn command or with the set command.SEE ALSOThe optional argument not can be used to negate a condition. Alternatively, the operator ! can be used for the same purpose.
all, for, printf, set, while