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?
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?
Using GNU sed:
foo=test
sed 's/.$/\U&/' <<< "$foo"
Using an extra variable:
foo=test
tmp="${foo: -1}"
echo "${foo:: -1}${tmp^}"