Converting the value of a variable to upper case with Bash 4
Let's take the built-in variable "USER".
$ echo $USER
victor
Converting first letter to capital:
$ echo ${USER^}
Victor
Converting all letters to capital:
$ echo ${USER^^}
VICTOR
Converting the first letter if matches letter (v for this example)
$ echo ${USER^v}
Victor
Converting any letter that matches (c for this example)
$ echo ${USER^^c}
viCtor
And of course we can apply a loop to convert the first character of all words in a string to capital:
$ var="this is a text title"
$ echo $var
this is a text title
$ for i in $(echo $var) ; do echo ${i^} ; done | tr '\n' ' ' ; echo -e "\r"
This Is A Text Title
Written by Victor Mendonca
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Related Tags
#bash
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#