Reference Manual

NAME

if - conditional command execution
SYNOPSIS
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).

Evaluation of the condition proceeds as follows:

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.pTrue if ifn is the primary interface
ifn.sTrue if ifn is the secondary interface
ifn.aTrue if ifn is the auxiliary interface
ifn.vTrue if ifn is the virtual WiFi interface
ifn.fTrue if ifn is the WiFi interface
ifn.wTrue if ifn is the best Windows interface
ifn.rTrue if ifn is the RAS Server interface
  
ifn.wifiTrue if ifn is a WiFi interface
ifn.vwifiTrue if ifn is a virtual WiFi interface
ifn.vwifi2True if ifn is a second virtual WiFi interface
ifn.mainTrue if ifn is a main Internet interface
ifn.internetTrue if ifn is an Internet interface
ifn.privateTrue if ifn is a private interface
ifn.auxTrue if ifn is an auxiliary Internet interface
ifn.vpnTrue if ifn is a VPN interface
ifn.pppoeTrue if ifn is a PPPoE interface
ifn.gatewayTrue if ifn has a gateway address
ifn.ipTrue 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.

NOTES
The current interface number ifn can be set with an ip ifn command or with the set command.

The optional argument not can be used to negate a condition. Alternatively, the operator ! can be used for the same purpose.

SEE ALSO
all, for, printf, set, while