DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
m4 macro processor

Conditionals

Arbitrary conditional testing is performed with the built-in ifelse. In its simplest form

   ifelse(a, b, c, d)
compares the two strings a and b. If a and b are identical, ifelse returns the string c. Otherwise, string d is returned. Thus, a macro called compare can be defined as one that compares two strings and returns yes or no, respectively, if they are the same or different:
   define(compare, `ifelse($1, $2, yes, no)')
Note the quotes, which prevent evaluation of ifelse from occurring too early. If the final argument is omitted, the result is null, so
   ifelse(a, b, c)
is c if a matches b, and null otherwise.

ifelse can actually have any number of arguments and provides a limited form of multiway decision capability. In the input

   ifelse(a, b, c, d, e, f, g)
if the string a matches the string b, the result is c. Otherwise, if d is the same as e, the result is f. Otherwise, the result is g.
Next topic: String manipulation
Previous topic: System command

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005