bash to uppercase code example
Example 1: bash transform uppercase to lowercase
Just use tr command to transform lowercase letters into uppercase as:
tr a-z A-Z < file.txt
echo 'HELLO' | tr A-Z a-z
Example 2: bash how to convert text to lowercase or uppercase
tolower(string)
toupper(string)
awk '{print tolower($0)}' input_file
awk '{print toupper($3)}' input_file
Example 3: bash convert string to uppercase
var=hello
echo ${var''}
HELLO
echo ${var'}
Hello
var2=BYE
echo ${var2,}
bye
echo ${var2,,}
bYE
echo $var | tr 'a-z' 'A-Z'
HELLO
Example 4: how to compare a character to uppercase in bash script
echo "enter a char"
read c
if [[ $c == [A-Z] ]];
then
echo "upper"
elif [[ $c == [a-z] ]];
then
echo "lower"
else
echo "Digit or special symbols!"
fi