Page
bash | string | uppercase | lowercase
Using Bash Parameter Expansion
Lowercase Conversion
To convert a string to lowercase, use the {variable,,} syntax:
string="Hello, World!"
lowercase_string="${string,,}"
echo "$lowercase_string"Output:
Output:
hello, world!Uppercase Conversion
To convert a string to uppercase, use the {variable^^} syntax:
string="Hello, World!"
uppercase_string="${string^^}"
echo "$uppercase_string"Output:
HELLO, WORLD!Using the `tr` Command
The tr (translate) command is a versatile tool for transforming text. It can be used for case conversion by specifying the input and output character sets:
Lowercase Conversion
Output:
Uppercase Conversion
Output:
Last updated