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
  • 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

3

Using GNU sed:

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

Using an extra variable:

foo=test tmp="${foo: -1}" echo "${foo:: -1}${tmp^}" 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.