start page | rating of books | rating of authors | reviews | copyrights

UNIX in a Nutshell: System V Edition

UNIX in a Nutshell: System V EditionSearch this book
Previous: Reference: .ieChapter 12
nroff and troff
Next: Reference: .ig
 

.if

.if [!]condition anything

If condition is true, do anything. The presence of an ! negates the condition. If anything runs over more than one line, it must be delimited by \{ and \}.

Conditions

o

True if the page number is odd.

e

True if the page number is even.

n

True if the processor is nroff.

t

True if the processor is troff.

"str1"str2"

True if str1 is identical to str2. Often used to test the value of arguments passed to a macro.

expr

True if the value of expression expr is greater than zero.

Expressions

Expressions typically contain number register interpolations and can use any of the following operators:

+ -

Addition, subtraction

/ *

Multiplication, division

%

Modulo

< >

Less than, greater than

<= >=

Less than or equal, greater than or equal

= ==

Equal

!

Logical negation

&

Logical AND

:

Logical OR

Note: expressions are evaluated left to right; there is no operator precedence. Parentheses may be supplied to force a particular evaluation order.

Example

Inside a macro definition, set the spacing and print the second argument. (The extra backslashes are necessary in \\$2. One backslash is stripped off when the macro is first read, so the second one is needed for it to be evaluated correctly when the macro is executed.)

.if t .nr PD 0.5v  \" Set spacing between ms paragraphs
.if !"\\$2"" \{ \" If arg 2 is non null, print it in bold
\fB\\$2\fP\}


Previous: Reference: .ieUNIX in a Nutshell: System V EditionNext: Reference: .ig
Reference: .ieBook IndexReference: .ig

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System