0

How can I convert last character of the string to upper case ?

ex:

foo=test
echo ${foo^}

this works for first character

Test 

I want the output to be

TesT

How does this work?

1
  • There is a very similar question here but couldn't find a dupe on SO. Commented May 7, 2019 at 15:39

1 Answer 1

2

Using GNU sed:

foo=test
sed 's/.$/\U&/' <<< "$foo"

Using an extra variable:

foo=test
tmp="${foo: -1}"
echo "${foo:: -1}${tmp^}"

Not the answer you're looking for? Browse other questions tagged or ask your own question.