BASH Arithmetic Expressions
Posted
by Arko
on Stack Overflow
See other posts from Stack Overflow
or by Arko
Published on 2010-03-25T17:07:50Z
Indexed on
2010/03/25
17:13 UTC
Read the original article
Hit count: 332
I had used several ways to do some simple integer arithmetic in BASH (3.2). But I can't figure out the best (preferred) way to do it.
result=`expr 1 + 2`
result=$(( 1 + 2 ))
let "result = 1 + 2"
What are the fundamental differences between those expressions?
Is there other ways to do the same?
Is the use of a tool like bc
mandatory for floating point arithmetic?
result=`echo "7/354" | bc`
© Stack Overflow or respective owner