Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting lowercase to uppercase in shell script

Tags:

shell

I tried to convert a lowercase string to uppercase and assign it to a variable using the following code

The script is written in .tn extension

set y a12
y_up=$( tr '[A-Z]' '[a-z]' <<< $y)
echo $y
echo $y_up

But I am getting the error

invalid command name "A-Z"
while executing
"A-Z"
invoked from within
"y_up=$( tr '[A-Z]' '[a-z]' <<< $y) "

How can I convert this?

like image 958
user3304726 Avatar asked Jun 05 '26 02:06

user3304726


1 Answers

BASH 4+ version has native way to convert sting to upper case:

str="Some string here"
upperStr="${str^^}"
like image 79
anubhava Avatar answered Jun 07 '26 22:06

anubhava