XP(1): evaluate expressions
__________________________________________________
USAGE
usage: xp [-DFLYqu] [expr]
-D: debug
-F: report known functions and exit
-L: debug lex
-Y: debug yacc
-q: do not print values as they are evaluated
-u: use unix out
DESCRIPTION
Xp evaluates the expression given as an argument, or those in
its standard input if none is given. When using standard input,
each line is parsed and evaluated as a single expression. The
expressions may involve file attributes. Thus, xp replaces the
venerable UNIX test command.
The usual arithmetic and logic operators can be used, Values in
operations are considered as unsigned integers, integers,
floating point numbers, strings, or booleans, depending on the
context.
The following functions are known to xp, all operate on floating
point numbers:
abs asin atanh cosh floor log2 sqrt trunc
acos asinh cbrt exp log sin tan Γ
acosh atan cos exp2 log10 sinh tanh
A name that starts with '%' is considered a conversion for Printf
and can be used as a function to print the argument with such
conversion.
Any name that is not a function name and is not a conversion can
be used as a function to ask for the value of a file attribute
with such name. The names r, w, and x can be used as attribute
names and evaluate to a boolean value indicating if the file has
any of the read, write, or execute permissions set.
Text enclosed in double quotes is understood always as a name.
Also, after calling a file attribute as a function, the next
non-blank word is understood as a name, including characters like
/, -, etc., which would become operators in other places. This is
a helper to specify file paths in a convenient way.
A string in square brackets represents a time. This can be used
with the relational operators to compare against attributes that
indicate times. The string may use any format understood by the
[cmd/opt(2)] package.
If the last computed yields a value of true the command exits
with success, and if it is false with failure. This, along with
flag -q, is useful to evaluate expressions as shell conditions
without printing their value.
EXAMPLES
See if the length of the file is greater than 3 Mbytes and print
y if it is.
; xp -q size afile '>' 3m && echo y
Print the mtime for a file
; xp mtime afile
2015-05-08 11:35:28
See if the file was changed since 2013-01-02 3pm
; xp mtime afile '>' '[2013-01-02 3pm]'
false
Print 4KiB as a 32bit binary number [
; xp '%064b (4 1024)' 00000000000000000001000000000000
]
SOURCE
+o [/zx/sys/src/clive/cmd/xp[
__________________________________________________
User's manual. Section 1. Copyright © LSUB 2014-2016