EXPR
Evaluate infix expression
- EXPR
Evaluate an integer expression and return its value as the command’s result. Nothing is printed unless the expression is invalid (
Invalid expression: <text>). The value is available afterwards as$?, but only until the next command line: when each command is sent with its ownbcmcmdcall,$?already reads 0 in the next call. Read it on the same line (expr …; echo $?), or test the value withif(see below).All arguments are joined without spaces, so
expr 1 + 2andexpr 1+2are the same. The text is limited to 127 characters; anything longer is silently cut off. Arithmetic is unsigned 32-bit. Operators, from highest to lowest precedence:( ); unary- + ~ !;* / %;+ -;<< >>;< <= > >=;== !=;&;^;|;&&;||(the same order as in C). Division or modulo by zero is an invalid expression. Numbers use the shell’s formats (0x, leading0,0b).Because the value is the command’s result:
only a value of 0 counts as success, which inverts the result in
if(writeif !"expr …"to test for non-zero);values that look like error codes (0xFFFFFFFF, 0xFFFFFFFE, …) are taken as errors: the shell may print
expr’s usage or a Failed to execute line;a line starting with
exprnever counts as a failure inside anrcloadscript.
Read-only.
Hardware-validated
drivshell> expr (1 << 4) + 2 drivshell> echo $? 0
Sent as two
bcmcmdcalls, as above, theechoprints 0, not 18. On one line it should print the value:Hardware-validated
drivshell> expr (1 << 4) + 2; echo $? 18
Built-in help
Parameters: <c-style arithmetic expression> Evaluates an expression and sets the result as the return value.Further reading
SDK-6.5.20 HSDK Getting Started Guide (GS-SDK6520-R), plus SDK-6.5.20/21/22 Release Notes (RN-SDK65xx-R), BCM_SDK命令.