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" 
3
  • [ "${code^^}" = "$favTeam" ], if your shell is bash 4.0 or newer. Commented Mar 23, 2020 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). Commented Mar 23, 2020 at 17:02
  • thank you very much, sir, that really helped me out in solving my problem. Commented Mar 23, 2020 at 17:22

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.