mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2026-01-16 10:11:01 +00:00
2.1 KiB
2.1 KiB
expr
expr [EXPRESSION]
expr [OPTIONS]
Print the value of EXPRESSION to standard output
After help
Print the value of EXPRESSION to standard output. A blank line below
separates increasing precedence groups.
EXPRESSION may be:
ARG1 | ARG2:ARG1if it is neither null nor 0, otherwiseARG2ARG1 & ARG2:ARG1if neither argument is null or 0, otherwise 0ARG1 < ARG2:ARG1is less thanARG2ARG1 <= ARG2:ARG1is less than or equal toARG2ARG1 = ARG2:ARG1is equal toARG2ARG1 != ARG2:ARG1is unequal toARG2ARG1 >= ARG2:ARG1is greater than or equal toARG2ARG1 > ARG2:ARG1is greater thanARG2ARG1 + ARG2: arithmetic sum ofARG1andARG2ARG1 - ARG2: arithmetic difference ofARG1andARG2ARG1 * ARG2: arithmetic product ofARG1andARG2ARG1 / ARG2: arithmetic quotient ofARG1divided byARG2ARG1 % ARG2: arithmetic remainder ofARG1divided byARG2STRING : REGEXP: anchored pattern match ofREGEXPinSTRINGmatch STRING REGEXP: same asSTRING : REGEXPsubstr STRING POS LENGTH: substring ofSTRING,POScounted from 1index STRING CHARS: index inSTRINGwhere anyCHARSis found, or 0length STRING: length ofSTRING+ TOKEN: interpretTOKENas a string, even if it is a keyword likematchor an operator like/( EXPRESSION ): value ofEXPRESSION
Beware that many operators need to be escaped or quoted for shells.
Comparisons are arithmetic if both ARGs are numbers, else lexicographical.
Pattern matches return the string matched between and or null; if
and are not used, they return the number of characters matched or 0.
Exit status is 0 if EXPRESSION is neither null nor 0, 1 if EXPRESSION
is null or 0, 2 if EXPRESSION is syntactically invalid, and 3 if an
error occurred.
Environment variables:
EXPR_DEBUG_TOKENS=1: dump expression's tokensEXPR_DEBUG_RPN=1: dump expression represented in reverse polish notationEXPR_DEBUG_SYA_STEP=1: dump each parser stepEXPR_DEBUG_AST=1: dump expression represented abstract syntax tree