0

here is the simple script that I have written in bash. In my script, I want the user input values to be in the upper case. As the values needed to be compared in upper case so I want the script to be written in such a way that in whichever case the user input i.e. upper or lower case, the values must be stored in upper case in the variable. My code be like:

favTeam="ENG"                                                                                                                                                   printf " --> (AUS) for Australia \n --> (BAN) for Bangladesh \n --> (NEP) for Nepal \n --> (IND) for India \n --> (ENG) for England\n "                         read -p "Please enter the code of your favourite country" code                                                                                                  
if [ "$code" == "$favTeam" ]                                                                                                                                    then
echo "The country you have choosen is England"                                                                                                                  else
echo "please try again next time"  
  • `[ "${code^^}" = "$favTeam" ]`, if your shell is bash 4.0 or newer. – Charles Duffy Mar 23 '20 at 17:01
  • (Using `==` in `[` is legal in bash, but it's a bad habit in general, because it isn't guaranteed to work with `/bin/sh`; use `=` as your string comparison operator in `[`, as it's [the only one guaranteed to work by the POSIX standard](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html)). – Charles Duffy Mar 23 '20 at 17:02
  • thank you very much, sir, that really helped me out in solving my problem. – Hardik Poudel Mar 23 '20 at 17:22

0 Answers0