sh Arithmetic Expansion Ternery Expressions

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

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


Got any sh Question?