Monthly Archive: February 2014

$(()) vs. `expr`

Just a quick note on the relative speed of $(()) vs. expr as a means of evaluating arithmetic expressions in bash: even though they’re (apparently) functionally equivalent, this:

for i in {1..10}; do n=expr $i + 10; echo $n; done

Takes about a full second to run (I can see it print the lines one at a time), whereas this:

for i in {1..10}; do n=$(($i + 10)); echo $n; done

pops out all at once. Tested in GNU bash, version 4.2.37(1)-release (x86_64-pc-linux-gnu).