Name

if

Synopsis

                  if 
                  (
                  condition
                  )
                  command1
[else
                  command2]

If condition is true, execute command1; otherwise, execute command2. condition can be an expression using any of the relational operators <, <=, = =, !=, >=, or >, as well as the pattern-matching operator ~. A series of commands must be put within braces.

Example

The following line determines whether the first word in each line starts with A, uppercase or lowercase:

                  if ($1 ~ /[Aa]*/)

Get Linux in a Nutshell, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.