$if()
DESCRIPTION
returns one string, if a logical expression is TRUE;
else another string, if the logical expression is FALSE
or:
returns a string, if a logical expression is TRUE;
else the string "<<NIL>>", if the logical expression is false
SYNOPSIS
$if(x,s1,s2)
or:
$if(x,s)
ARGUMENTS
x - a logical condition, or conditional expression
s1 - a string, or string expression
s2 - a string, or string expression
or:
x - a logical condition, or conditional expression
s - a string, or string expression
EXAMPLES
set_datestamp // set $datestamp = "991215", for example
set $datestamp = $right($text(#year()),2) .
$if(#month()<10, "0", "") .
$text(#month()) . $if(#day()<10, "0", "") .
$text(#day())
rule // if oversized, truncate
if #size > #abs(#maxsize)
=outputmail "Truncating $name, was $text(#size) " .
$if(#binary, "KB", "lines")
=execwait "=trunc " . $if(#binary, "0", "100") . " $name"
endif
rule
if ! #defined(#passwd[$inlin])
output mail $if($inlin eq "","+",$inlin) .
" in /etc/shadow, not in /etc/passwd"
else // if ! #defined(#shadow[$inlin])
output mail $if($inlin eq "","+",$inlin) .
" in /etc/passwd, not in /etc/shadow"
endif
# if nisclient
set $nisentry = $command("=ypmatch $inlin passwd 2>/dev/null")
if $nisentry ne ""
output mail "NIS passwd entry: $nisentry"
else
output mail $if($inlin eq "","+",$inlin) .
" not found in NIS passwd"
endif
# endif
output mail "=newline"
rule
if $access !~ $prm
=execwait "=chmod $mod $dev"
// if $access =~ "^.....w..w."
=outputmail "$name permissions of $access are wrong" .
$if(#defined(%access)," (were %access),",",") .
" changed to $prm"
// endif
endif
rule
if $owner ne $own
=execwait "=chown $own $dev"
=outputmail "$name owner $owner is wrong" .
$if(#defined(%owner)," (was %owner),",",") .
" changed to $own"
endif
rule
if $group !~ $grp
=execwait "=chgrp $grp $dev"
=outputmail "$name group $group is wrong" .
$if(#defined(%group)," (was %group),",",") .
" changed to $grp"
endif
SEE ALSO
String Functions
Numerical Functions