bash - How to uppercase/lowercase a bash variable

in «tip» by Michael Beard
Tags: , , , ,

Found a couple places (took me a minute to figure out what they meant - sort of thick at times).

Here is the code:

#### https://linuxhint.com/bash_lowercase_uppercase_strings/
#### upper-case the passed in choice 
####  - have to use for bash 3.2.57
####  - can't use nice bash 4+ way - silly macOS
#
MY_CHOICE=`echo $1 | tr "[:lower:]" "[:upper:]"`
echo "choice:  $MY_CHOICE"

What confused me at first was what was passed to tr -- the :lower: and :upper: are what direction you want the case to go. Initially, it was upper/lower in the example I used, but when I saw the other example, it made sense. It had these examples:

echo "stRING" | awk '{print toupper($0)}'

echo "STRING" | tr "[A-Z]" "[a-z]" # upper to lower

Then I had to figure out how to assign the result of an echo to a bash variable as well.

How to assign the result of echo to a variable in bash script