How to Capitalize Words Using a Bash Script (using an Example)

On a macOS you’ll need to install gnu-sed (e.g., brew install gnu-sed), which is invoked using “gsed.” Otherwise, try the below script on your *nix system.

while read line
echo -e “$line” | sed -r ‘s/\<./\U&/g’
done < “${1:-/dev/stdin}”

Topics of interest: parameter substitution, pipes in bash, and uppercasing in sed.