Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
syntax:arith_expr [2011/03/22 06:12]
fgrose [Arithmetic expressions and return codes]
syntax:arith_expr [2017/02/11 14:22] (current)
fgrose [Table] meaning of ternary operator
Line 11: Line 11:
   * [[syntax:​arrays | array indexing]]   * [[syntax:​arrays | array indexing]]
   * [[syntax:​ccmd:​conditional_expression | conditional expressions]]   * [[syntax:​ccmd:​conditional_expression | conditional expressions]]
 +  * Assignment statements, and arguments to declaration commands of variables with the integer attribute.
  
 These expressions are evaluated following some rules described below. The operators and rules of arithmetic expressions are mainly derived from the C programming language. These expressions are evaluated following some rules described below. The operators and rules of arithmetic expressions are mainly derived from the C programming language.
  
-This article describes the theory of the used syntax and the behaviour.\\ +This article describes the theory of the used syntax and the behaviour. To get practical examples without big explanations,​ see [[http://mywiki.wooledge.org/​BashGuide/CompoundCommands#​Arithmetic_Evaluation ​this page on Greg's wiki]].
-To get practical examples without big explanations,​ see [[http://​wooledge.org/​mywiki/ArithmeticExpression ​the article ​on Greg's wiki]].+
  
 ===== Constants ===== ===== Constants =====
Line 164: Line 164:
 ==== Misc ==== ==== Misc ====
  
-^Operator^Description^ +^ Operator ​                     ^ Description ​                                                                          ​
-|''​id++''​|**post-increment** of the variable ''​id''​ (not required by POSIX(r))| +| ''​id++'' ​                     | **post-increment** of the variable ''​id''​ (not required by POSIX(r)) ​                 
-|''​id<​nowiki>​--</​nowiki>​''​|**post-decrement** of the variable ''​id''​ (not required by POSIX(r))| +| ''​id%%--%%'' ​                 | **post-decrement** of the variable ''​id''​ (not required by POSIX(r)) ​                 
-|''​++id''​|**pre-increment** of the variable ''​id''​ (not required by POSIX(r))| +| ''​++id'' ​                     | **pre-increment** of the variable ''​id''​ (not required by POSIX(r)) ​                  ​
-|''​<​nowiki>​--</​nowiki>​id''​|**pre-decrement** of the variable ''​id''​ (not required by POSIX(r))| +| ''​%%--%%id'' ​                 | **pre-decrement** of the variable ''​id''​ (not required by POSIX(r)) ​                  ​
-|''​+''​|unary plus| +| ''​+'' ​                        ​| unary plus                                                                            
-|''​-''​|unary minus| +| ''​-'' ​                        ​| unary minus                                                                           ​
-|''<​EXPR>​ ? <​EXPR>​ : <​EXPR>''​|conditional (ternary) operator| +| ''<​EXPR>​ ? <​EXPR>​ : <​EXPR>'' ​ | conditional (ternary) operator ​\\ <​condition>​ ? <​result-if-true>​ : <​result-if-false>  ​
-|''<​EXPR>​ , <​EXPR>''​|expression list| +| ''<​EXPR>​ , <​EXPR>'' ​          ​| expression list                                                                       ​
-|''​( <​EXPR>​ )''​|subexpression (to force precedence)|+| ''​( <​EXPR>​ )'' ​               | subexpression (to force precedence) ​                                                  ​|
  
  
Line 205: Line 205:
 Bash's overall language construct is based on exit codes or return codes of commands or functions to be executed. ''​if''​ statements, ''​while''​ loops, etc., they all take the return codes of commands as conditions. Bash's overall language construct is based on exit codes or return codes of commands or functions to be executed. ''​if''​ statements, ''​while''​ loops, etc., they all take the return codes of commands as conditions.
  
-Now the problem is: The return codes (0 means "​TRUE"​ or "​SUCCESS",​ not 0 means "​FALSE"​ or "​FAILURE"​) don't correspond to the meaning of the result of an arithmetic expression (0 means "TRUE", not 0 means "FALSE").+Now the problem is: The return codes (0 means "​TRUE"​ or "​SUCCESS",​ not 0 means "​FALSE"​ or "​FAILURE"​) don't correspond to the meaning of the result of an arithmetic expression (0 means "FALSE", not 0 means "TRUE").
  
 That's why all commands and keywords that do arithmetic operations attempt to **translate** the arithmetical meaning into an equivalent return code. This simply means: That's why all commands and keywords that do arithmetic operations attempt to **translate** the arithmetical meaning into an equivalent return code. This simply means:
  • syntax/arith_expr.1300774336.txt
  • Last modified: 2011/03/22 06:12
  • by fgrose