The expr command is used to evaluate an expression and output the corresponding value. It could be used for example to use the terminal as a calculator:
$ expr 80 - 25
55
$ expr 80 / 25
3
Note that there is a space between the different arguments, otherwise the expression might not be evaluated properly.
It can be used as well for string operations and boolean operations
$ expr length "abc"
3
$ expr 1 "&" 0
0
$ expr 80 - 25
55
$ expr 80 / 25
3
Note that there is a space between the different arguments, otherwise the expression might not be evaluated properly.
It can be used as well for string operations and boolean operations
$ expr length "abc"
3
$ expr 1 "&" 0
0
For Bash shell, there is no need to use expr
RépondreSupprimeryou can simply use :
$(( 80 / 25 ))
or
$[ 80 / 25 ]
example:
$ var=$[ 80 / 25 ]
$ echo $var
3
Thank you for the info. This doesn't work with korn shell though.
Supprimer