bright=$(brightnessctl get) state=-1 thresh=(0 1 2 3 5 9 15 27 46 80 139 240 415 717 1240 2145 3710 6418 11100 19200) for i in ${!thresh[@]}; do if [ $bright -ge ${thresh[$i]} ] then state=$i fi done new=$(($1 + $state)) if [ $new -ge 0 ] && [ $new -le 20 ] then echo $(brightnessctl set ${thresh[$new]}) fi