#!/bin/bash
str="75.00 W, 170.00 W"
function str_check {
pow_array=()
regexp='([0-9]+)\.[0-9]+[[:space:]]W,[[:space:]]([0-9]+)\.[0-9]+[[:space:]]W'
[[ $str =~ $regexp ]] && for (( i = 0; i < 3; i++ )); do
pow_array+=("${BASH_REMATCH[$i]}")
done
if [ "$1" -lt ${pow_array[1]} ]; then
echo "Available power limit is ${pow_array[0]}"
echo "Setting up ${pow_array[1]}"
elif [ "$1" -gt "${pow_array[2]}" ]; then
echo "Available power limit is ${pow_array[0]}"
echo "Setting up ${pow_array[2]}"
else
echo "All good, setting up $1"
fi
}
str_check "70"
str_check "100"
str_check "200"
IyEvYmluL2Jhc2gKc3RyPSI3NS4wMCBXLCAxNzAuMDAgVyIKZnVuY3Rpb24gc3RyX2NoZWNrIHsKICAgIHBvd19hcnJheT0oKQogICAgcmVnZXhwPScoWzAtOV0rKVwuWzAtOV0rW1s6c3BhY2U6XV1XLFtbOnNwYWNlOl1dKFswLTldKylcLlswLTldK1tbOnNwYWNlOl1dVycKICAgIFtbICRzdHIgPX4gJHJlZ2V4cCBdXSAmJiBmb3IgKCggaSA9IDA7IGkgPCAzOyBpKysgKSk7IGRvCiAgICAgICAgcG93X2FycmF5Kz0oIiR7QkFTSF9SRU1BVENIWyRpXX0iKQogICAgZG9uZQogICAgaWYgWyAiJDEiIC1sdCAke3Bvd19hcnJheVsxXX0gXTsgdGhlbgogICAgICAgIGVjaG8gIkF2YWlsYWJsZSBwb3dlciBsaW1pdCBpcyAke3Bvd19hcnJheVswXX0iCiAgICAgICAgZWNobyAiU2V0dGluZyB1cCAke3Bvd19hcnJheVsxXX0iCiAgICBlbGlmIFsgIiQxIiAtZ3QgIiR7cG93X2FycmF5WzJdfSIgXTsgdGhlbgogICAgICAgIGVjaG8gIkF2YWlsYWJsZSBwb3dlciBsaW1pdCBpcyAke3Bvd19hcnJheVswXX0iCiAgICAgICAgZWNobyAiU2V0dGluZyB1cCAke3Bvd19hcnJheVsyXX0iCiAgICBlbHNlCiAgICAgICAgZWNobyAiQWxsIGdvb2QsIHNldHRpbmcgdXAgJDEiCiAgICBmaQp9CgpzdHJfY2hlY2sgIjcwIgpzdHJfY2hlY2sgIjEwMCIKc3RyX2NoZWNrICIyMDAi