command line - bash expression type - Ask Ubuntu


what difference between bash expression type? trying answer question how increment variable in bash, seems ways same. wonder if of them backward compatibility?

here's way found can increment variable. work in bash expression type follows replacing expression 1 of these (except last one).

var=var+1 var=$((var+1)) var=$((var))+1 var=${var}+1 var=$var+1 var+=1 ++var var++ 
  • let expression
  • ((expression))
  • $((expression))
  • `expression`

seams start new bash environment, inheriting current one, not affect , not support ++var , var++. if invoke so: `((expression)); echo $var`

so basically, $((expression)) seems able others can do, last 1 (`expression`). affect local environment.

((expression))                expression   evaluated  according rules described               below under arithmetic evaluation.  if value of  expres‐               sion   non-zero, return status 0; otherwise return               status 1.  equivalent let "expression".         [[ expression ]]               return status of 0 or 1 depending on   evaluation  of                conditional  expression expression.  expressions composed of               primaries described  below  under  conditional  expressions.               word  splitting  , pathname expansion not performed on               words between [[ ,  ]];  tilde  expansion,  parameter  ,               variable  expansion, arithmetic expansion, command substitution,               process substitution, , quote removal  performed.   condi‐               tional operators such -f must unquoted recognized               primaries. 

this covers basics regarding bash expression types , bash man page. more arithmetic expressions see this.

sources:

man bash

http://www.softpanorama.org/scripting/shellorama/arithmetic_expressions.shtml


Comments

Popular posts from this blog

download - Firefox cannot save files (most of the time), how to solve? - Super User

windows - "-2146893807 NTE_NOT_FOUND" when repair certificate store - Super User

sql server - "Configuration file does not exist", Event ID 274 - Super User