How to convert lowercase to UPPERCASE in a bash shell script built-in

The first thing that we need to do is create the script with our desired code. Let’s say that we want to convert “example” into “EXAMPLE”. There is a solution in the Bash shell.

Let us use the power of Bash here, The script does this by using the built-in ${my_variable^^} (the carrot symbol, two times)

Example of changing the case from lower to upper:

Step #1:- Set a variable with a lowercase value.

dev@codetryout:~$ my_variable=codetryout

Step #2:- Print the variable, before changing the character case.

dev@codetryout:~$ echo $my_variable
codetryout

Step #3:- Change the case to uppercase (change to all capital letters) and print again:

dev@codetryout:~$ echo ${my_variable^^}
CODETRYOUT

This is very useful when you want to process any user input, regardless of its case. Here is another example.

# Entering all lowercase - yes
dev@codetryout:~$ read userinput
yes

dev@codetryout:~$ [[ ${userinput^^} == YES ]] && echo YES
YES


# Entering Yes, in mixed case - Yes
dev@codetryout:~$ read userinput
Yes

dev@codetryout:~$ [[ ${userinput^^} == YES ]] && echo YES
YES

# Entering all in uppercase - YES
dev@codetryout:~$ read userinput
YES

dev@codetryout:~$ [[ ${userinput^^} == YES ]] && echo YES
YES

This guide explained shell scripts to convert string to uppercase. I hope this is useful for you, if you have questions, please let us know.