Bash case statement with number ranges -


this question has answer here:

i in need of assistance cannot life of me seem understand bash case statements. i'm trying input user, annual income, , reply respective tax bracket. cannot seem cases work range of numbers. appreciated. thanks. here code far:

#!/bin/bash  echo -e "what annual income? " read annual_income  case $annual_income in      0) echo "you have no taxable income." ;;     [24100-42199]) echo "with annual income of $annual_income, in lowest income tax bracket total effective federal tax rate of 1.5%." ;;     [42200-65399]) echo "with annual income of $annual_income, in second income tax bracket total effective federal tax rate of 7.2%." ;;     [65400-95499]) echo "with annual income of $annual_income, in middle income tax bracket total effective federal tax rate of 11.5%." ;;     [95500-239099]) echo "with annual income of $annual_income, in fourth income tax bracket total effective federal tax rate of 15.6%." ;;     [239100-1434900]) echo "with annual income of $annual_income, in highest income tax bracket total effective federal tax rate of 24%." ;; esac 

the case statement understands shell patterns , not number ranges. rewrite program follows:

#!/bin/bash  echo -e "what annual income? " read annual_income  if (($annual_income == 0))      echo "you have no taxable income." elif ((24100 <= $annual_income && $annual_income <= 42199))     echo "with annual income of $annual_income, in lowest income tax bracket total effective federal tax rate of 1.5%." elif ((42200 <= $annual_income && $annual_income <= 65399))      echo "with annual income of $annual_income, in second income tax bracket total effective federal tax rate of 7.2%." elif ((65400 <= $annual_income && $annual_income <= 95499))     echo "with annual income of $annual_income, in middle income tax bracket total effective federal tax rate of 11.5%." elif ((95500 <= $annual_income && $annual_income <= 239099))      echo "with annual income of $annual_income, in fourth income tax bracket total effective federal tax rate of 15.6%." elif ((239100 <= $annual_income && $annual_income <= 1434900))       echo "with annual income of $annual_income, in highest income tax bracket total effective federal tax rate of 24%." fi 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -