#!/bin/bash set -e # Description: Capitalize every input words. function capitalizeFirstChar() { local string=$1 # Capitalize first character. first_char=${string:0:1} first_char=$(echo "${first_char}" | tr '[:lower:]' '[:upper:]') # Get the full string except the 1st character. right_side=${string:1} echo -n "${first_char}${right_side} " } # Capitalize every input words. for arg in "${@}"; do capitalizeFirstChar "${arg}" done
Output
$./capitalize.sh this is a test This Is A Test