+subject: expr - evaluate expressions in akanga
AKANGAEXPR(1) AKANGAEXPR(1)
NAME
expr - evaluate expressions in akanga
SYNOPSIS
expr [-e] [expr...]
DESCRIPTION
The expr command evaluates arithmetic expressions in
akanga(1), similiar to the external expr(1). Each given
expression is evaluated and, if the -e option is given,
the result of it is printed.
The value of the last expression defines the exit code: If
it's value is 0 the exit code is 1 and 0 otherwise.
OPERANDS
expr accepts numbers and strings as operands, operands are
coerced to the data types an operator expects. Numbers
may begin with 0x of a 0 in which case the number is
interpreted as hexadecimal or octal number. Otherwise
expr expects numbers to of the form base#number.
Strings are usually quoted with double quotes ``"'' but
you may use single quotes ``''' as well. Within a quoted
string expr recognizes the following escape sequences:
\ooo the character in octal representation
\0xhh the character in hexadecimal representation
\n newline
\t tabulator
Usually the expression arguments given to expr will be
enclosed in single quotes, so I don't expect much confu-
sion with that backslash quoting. expr won't place the
characters 0x00 or 0x01 inside a string. These characters
are silently dropped.
Indexed and non-indexed shell variables are accepted on
both sides of an assignment. Indices may be given with
either () or [] but if parentheses are used the variable
name is first matched again function names. Accessing an
non-existing index prints an error message. If a non-
indexed variable is a list, expr uses the flat string rep-
resentation of that list. expr does not work on lists.
Wildcards
The match operator ~ and the glob() function use the usual
wildcard characters ``*'', ``?'' and ``['' for pattern
matching. These wildcard characters cannot be quoted to
use them literally in the pattern. This would reintroduce
input reinterpretation to the current version of expr.
expr should work with strings as found in akanga instead
but actually it doesn't.
OPERATORS
The following operators are built into expr, the list
shows the operators in group of equal precedence in order
of decreasing precedence.
var #var var[] var()
variable, number of elements and indexed array
variable
( ) expression grouping
+ - ! ~
unary plus and minus, logical not and binary invert
* / % ~|
multiplication, division, modulo and binary xor
+ - addition and subtraction
^ string concatenation
^~ string wildcard match
<< >> left and right shift
^== ^!= ^>= ^> ^< ^<=
equality, inequality, greater or equal, greater,
less and less or equal string comparisions
== != >= > < <=
equality, inequality, greater or equal, greater,
less and less or equal numeric comparisions
&& & logical and, binary and
|| | logical or, binary and
? : conditional expression
, sequential execution
= assignment
The operators behave as in other languages like C or
awk(1). Operands with higher precedence are computed
first and parentheses can be used to group expressions.
FUNCTIONS
argc() returns the number of command line arguments.
argv(k)
returns the k-th command line argument.
basename(filename)
returns the filename portion of filename.
dirname(filename)
returns the dir portion of filename.
glob(pattern)
returns a string listing all filenames matching
pattern. The filenames are space separated.
index(string, sub)
returns the postion in string at which sub starts
or 0 if sub doesn't appear in string.
rindex(string, sub)
returns the rightmost postion in string at which
sub starts or 0 if sub doesn't appear in string.
seq(start, end, inc)
returns a string containing the number sequence
beginning from start to end with an increment of
inc. The sequence stops if in encouters a value
greater than end.
stat(what, filename)
returns filesystem information about file depending
on what:
-a access time of file.
-c creation time of file.
-e returns true if file exists, otherwise
false.
-g group id of file.
-m modification time of file.
-o owner's user id of file.
-p file permision of file as four octal digits.
-q file permision of file as six octal digits.
-s size in bytes of file.
-u device and inode of file.
If what doesn't match the above list the shell
prints an error message. If file doesn't exist or
the stat(1) call fails for some reason (e.g.
insuffient permissions) stat return -1.
Access, creation and modication times are returned
in number of seconds since 1.1.1970.
strftime(format, time)
return the formatted string of the given time (in
seconds from 01 January 1970). For a description
of format see strftime(3). If time is `1' the cur-
rent system's time is used.
strlen(string)
returns the length of string.
strlwr(string)
returns string in lowercase letters.
strupr(string)
returns string in uppercase letters.
substr(string, start [, len])
returns the substring from string string beginning
at start with len characters.
systime()
returns the system time in number of seconds from
1970.
test(condition, file [, list0
returns true (1) or false (0) depending on the test
condition:
-b true if file is a block device.
-c true if file is a character device.
-d true if file is a directory.
-e true if file exists.
-f true if file is a regular file.
-g true if file has it's setgid bit set.
-k true if file has it's sticky bit set.
-L true if file is a symbolic link.
-p true if file is a named pipe.
-r true if file is readable.
-s true if file is a non-empty regular file.
-S true if file is a socket.
-u true if file has it's setuid bit set.
-w true if file is writeable.
-x true if file is executable.
-O true if file is owned by the effective user
id.
-G true if file is owned by the effective group
id.
The following binary operations are defined. list
may be a space separated list of filenames. If any
of the files in list does not exist the expression
is false.
-nt is true is file is newer than each file in
list.
-ot is true if file is older than each file in
list.
If any other test condition is given the shell ter-
minates with an error message.
SEE ALSO
rc(1), akanga(1).
7 August 1999 AKANGAEXPR(1)