sh Arithmetic Expansion Ternery Expressions


Example

Absolute value:

$ for n in -8 -2 0 3 4; do
>     echo $((n<0?-n:n))
> done
8
2
0
3
4

Fix variable range:

$ min=2
$ max=4
$ for n in 1 2 3 4 5; do
>     echo $((n<min?min:n>max?max:n))
> done
2
2
3
4
4