User's manual. Section 1.

XP(1): evaluate expressions


USAGE

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:

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

SOURCE

  • [/zx/sys/src/clive/cmd/xp[


User's manual. Section 1.