fork download
  1. #!/bin/bash
  2. str="75.00 W, 170.00 W"
  3. function str_check {
  4. pow_array=()
  5. regexp='([0-9]+)\.[0-9]+[[:space:]]W,[[:space:]]([0-9]+)\.[0-9]+[[:space:]]W'
  6. [[ $str =~ $regexp ]] && for (( i = 0; i < 3; i++ )); do
  7. pow_array+=("${BASH_REMATCH[$i]}")
  8. done
  9. if [ "$1" -lt ${pow_array[1]} ]; then
  10. echo "Available power limit is ${pow_array[0]}"
  11. echo "Setting up ${pow_array[1]}"
  12. elif [ "$1" -gt "${pow_array[2]}" ]; then
  13. echo "Available power limit is ${pow_array[0]}"
  14. echo "Setting up ${pow_array[2]}"
  15. else
  16. echo "All good, setting up $1"
  17. fi
  18. }
  19.  
  20. str_check "70"
  21. str_check "100"
  22. str_check "200"
Success #stdin #stdout 0s 19736KB
stdin
Standard input is empty
stdout
Available power limit is 75.00 W, 170.00 W
Setting up 75
All good, setting up 100
Available power limit is 75.00 W, 170.00 W
Setting up 170