1fmlexpr(1F)                      FMLI Commands                     fmlexpr(1F)
2
3
4

NAME

6       fmlexpr - evaluate arguments as an expression
7

SYNOPSIS

9       fmlexpr arguments
10
11

DESCRIPTION

13       The  fmlexpr  function  evaluates its arguments as an expression. After
14       evaluation, the result is written on the standard output. Terms of  the
15       expression must be separated by blanks. Characters special to FMLI must
16       be escaped. Note that  30 is returned to indicate a zero value,  rather
17       than  the null string. Strings containing blanks or other special char‐
18       acters should be quoted. Integer-valued arguments may be preceded by  a
19       unary  minus  sign. Internally, integers are treated as 32-bit, 2s com‐
20       plement numbers.
21
22
23       The operators and keywords are listed below. Characters that need to be
24       escaped  are  preceded  by \. The list is in order of increasing prece‐
25       dence, with equal precedence operators grouped within {} symbols.
26

USAGE

28   Expressions
29       expr \| expr
30
31           Returns the first expr if it is  neither   NULL  nor  0,  otherwise
32           returns the second expr.
33
34
35       expr \& expr
36
37           Returns  the  first  expr  if neither expr is  NULL or 0, otherwise
38           returns 0.
39
40
41       expr { =, \>, \>=, \<, \<=, != } expr
42
43           Returns the result of an integer comparison if both  arguments  are
44           integers, otherwise returns the result of a lexical comparison.
45
46
47       expr { +, − } expr
48
49           Addition or subtraction of integer-valued arguments.
50
51
52       expr { *, /, % } expr
53
54           Multiplication,  division, or remainder of the integer-valued argu‐
55           ments.
56
57
58       expr : expr
59
60           The matching operator : (colon) compares the  first  argument  with
61           the  second  argument  which  must be a regular expression. Regular
62           expression syntax is the same as that of  ed(1),  except  that  all
63           patterns  are  "anchored" (that is, begin with ^) and, therefore, ^
64           is not a special character, in that context. Normally, the matching
65           operator returns the number of bytes matched (0 on failure). Alter‐
66           natively, the (...) pattern symbols can be used to return a portion
67           of the first argument.
68
69

EXAMPLES

71       Example 1 Incrementing a variable
72
73
74       Add 1 to the variable a:
75
76
77         example% fmlexpr $a + 1 | set -l a
78
79
80
81       Example 2 Setting a variable equal to a filename
82
83
84       For $a equal to either /usr/abc/file or just file:
85
86
87         example% fmlexpr  $a  :   .*/\(.*\)  \|  $a
88
89
90
91
92       returns  the last segment of a path name (that is, file). Watch out for
93       / alone as an argument: fmlexpr will take it as the  division  operator
94       (see NOTES below).
95
96
97       Example 3 A better representation of Example 2
98
99         example% fmlexpr  //$a  :  .*/\(.*\)
100
101
102
103
104       The  addition  of  the // characters eliminates any ambiguity about the
105       division operator (because it makes it  impossible  for  the  left-hand
106       expression  to be interpreted as the division operator), and simplifies
107       the whole expression.
108
109
110       Example 4 Counting characters in a variable
111
112
113       Return the number of characters in $VAR:
114
115
116         example% fmlexpr $VAR : .*
117
118
119

EXIT STATUS

121       As a side effect of expression evaluation, fmlexpr returns the  follow‐
122       ing exit values:
123
124       0    if the expression is neither NULL nor 0 (that is, TRUE)
125
126
127       1    if the expression is NULL or 0 (that is, FALSE)
128
129
130       2    for invalid expressions (that is, FALSE).
131
132

ATTRIBUTES

134       See attributes(5) for descriptions of the following attributes:
135
136
137
138
139       ┌─────────────────────────────┬─────────────────────────────┐
140ATTRIBUTE TYPE         ATTRIBUTE VALUE        
141       ├─────────────────────────────┼─────────────────────────────┤
142       │Availability                 │SUNWcsu                      │
143       └─────────────────────────────┴─────────────────────────────┘
144

SEE ALSO

146       ed(1), expr(1), set(1F), sh(1), attributes(5)
147

DIAGNOSTICS

149       syntax error            for operator/operand errors
150
151
152       non-numeric argument    if arithmetic is attempted on such a string
153
154
155
156       In  the  case of syntax errors and non-numeric arguments, an error mes‐
157       sage will be printed at the current cursor  position.  Use  refresh  to
158       redraw the screen.
159

NOTES

161       After  argument  processing by FMLI, fmlexpr cannot tell the difference
162       between an operator and an operand except by the value. If $a is an  =,
163       the command:
164
165         example% fmlexpr $a = =
166
167
168
169
170       looks like:
171
172         example% fmlexpr = = =
173
174
175
176
177       as  the  arguments are passed to fmlexpr (and they will all be taken as
178       the = operator). The following works, and returns TRUE:
179
180         example% fmlexpr X$a = X=
181
182
183
184
185
186SunOS 5.11                        5 Jul 1990                       fmlexpr(1F)
Impressum