Friday, July 12, 2024

Convert strings to Upper or Lower Case in bash

Very simple way to convert strings to all Upper or Lower case in bash without using any of the other tools like awk or sed
myStr="Test"
myLowerCaseStr=${myStr,,}
myUpperCaseStr=${myStr^^}
echo "String: ${myStr}"
echo "Lower Case String: ${myLowerCaseStr}"
echo "Upper Case String: ${myUpperCaseStr}"
The output would be as follows:
String: Test
Lower Case String: test
Upper Case String: TEST

LinkWithin

Related Posts Plugin for WordPress, Blogger...