Bash's ArithmeticExpression
2013-12-08 20:10
211 查看
【Bash's ArithmeticExpression】
let command:
In addition to the let command, one may use the (( )) syntax to enforce an arithmetic context. If there is a $ (dollar sign) before the parentheses, then a substitution is performed (more on this below). White space is allowed inside (( )) with much greater leniency than with normal assignments, and variables inside (( )) don't require $(because string literals aren't allowed):
(( )) without the leading $ is a Bash-only feature. $(( )) substitution is allowed in the POSIX shell. As one would expect, the result of the arithmetic expression inside the$(( )) is substituted into the original command. Here are some examples of the use of the arithmetic substitution syntax:
参考:http://bash.cumulonim.biz/ArithmeticExpression.html
let command:
let a=17+23 echo "a = $a" # Prints a = 40 let a=17 + 23 # WRONG let a="17 + 23" # Right let a=28/6 echo "a = $a" # Prints a = 4
In addition to the let command, one may use the (( )) syntax to enforce an arithmetic context. If there is a $ (dollar sign) before the parentheses, then a substitution is performed (more on this below). White space is allowed inside (( )) with much greater leniency than with normal assignments, and variables inside (( )) don't require $(because string literals aren't allowed):
(( )) without the leading $ is a Bash-only feature. $(( )) substitution is allowed in the POSIX shell. As one would expect, the result of the arithmetic expression inside the$(( )) is substituted into the original command. Here are some examples of the use of the arithmetic substitution syntax:
use declare command to set the type of a variant declare -i b # Declare b as an integer
参考:http://bash.cumulonim.biz/ArithmeticExpression.html
相关文章推荐
- 【CodeForces】115D Unambiguous Arithmetic Expression 组合数学
- sh: arithmetic expression: expecting primary
- Evaluate the value of an arithmetic expression in Reverse Polish Notation.
- Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are+,-,*,
- Variables and Arithmetic Expression
- Evaluate the value of an arithmetic expression in Reverse Polish Notation.
- Evaluate the value of an arithmetic expression in Reverse Polish Notation.
- OOD - Arithmetic Expression Tree
- sicily 递归练习 1005. Arithmetic Expression Evaluation
- Evaluate the value of an arithmetic expression in Reverse Polish Notation.
- Unambiguous Arithmetic Expression CodeForces - 115D
- ACM Arithmetic Expression
- 纠结了一天多的问题arithmetic overflow error converting expression to data type datetime
- 义 unsigned char *pImage;报错错误: expected expression before ‘unsigned’
- 【正则表达式判断】Regular Expression Matching
- Regular Expression Matching
- 【分治】UVa 11129 An antiarithmetic permutation
- javascript中expression的用法整理
- 基类的参考Expression能传一个lambda表达式
- 【LeetCode】Regular Expression Matching