convert 460 B

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/env bash
  2. # grugly@sdf
  3. # Converts things to other things.
  4. source '../say.sh'
  5. msg='Usage: !convert <f2c|c2f> number'
  6. src="$2"
  7. con="$3"
  8. inp="$4"
  9. case "$con" in
  10. 'f2c')
  11. if [[ "$inp" =~ [0-9]$ ]]; then
  12. msg="$(echo "scale=2;(5/9)*($inp-32)"|bc)°C"
  13. fi
  14. ;;
  15. 'c2f')
  16. if [[ "$inp" =~ [0-9]$ ]]; then
  17. msg="$(echo "scale=2;((9/5)*$inp)+32"|bc)°F"
  18. fi
  19. ;;
  20. esac
  21. say "$src" "$msg"