| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

expr

Page history last edited by PBworks 17 years, 9 months ago

expr

expr 3 + 5
    returns 8

expr 5 % 3
    returns 2

expr 1 / 0

    returns the error message, expr: division by zero
    Illegal arithmetic operations not allowed.

expr 5 * 3

    returns 15

    The multiplication operator must be escaped when used in an arithmetic expression with expr.
y=`expr $y + 1`

    Increment a variable, with the same effect as let y=y+1 and y=$(($y+1)). This is an example of arithmetic expansion.
z=`expr substr $string $position $length`



Outras formas de incrementar variáveis

   O comando expr é muito conhecido pelos programadores shell (bash, ksh, sh, etc), mas a sua   utilização, na maioria das vezes, restringe-se ao comando abaixo:

contador=`expr $contador + 1`

Este comando irá incrementar o valor da variável contador em 1, outras formas de alcançar o mesmo objetivo em bash seriam:

let contador++
contador=$((contador+1))

Comments (0)

You don't have permission to comment on this page.