I need to accept an email id and Full name in a script, and in case the Full name is not provided, I need to generate the name from the email id. Something like this:Case 1:EmailID: user.name@domainname.comFull Name: User NameCase 2:EmailID: user.name2@domainname.comFull Name: User Name2Case 3:EmailID: this.is.a.very.long.email.id@domainname.comFull Name: This Is A Very Long Email IdThis I have been able to achieve using the following steps:EMAIL_ADDRESS=$1ID=(`echo $EMAIL_ADDRESS | cut -d'@' -f1| tr '.' ' '`)NEW_ID=()NUM=0for IN_VAL in ${ID[@]}do    NEW_ID[$NUM]=`echo ${IN_VAL^}`    NUM=$((++NUM))doneecho ${NEW_ID[@]}I am on BASH version 4.1.2I think there has to be a better way to achieve this. Also, I already see a problem in this as I am assuming the  field separator is going to be dot (.) character and not anything else like underscore (_) or hyphen (-) or anything else. If there is a better way to do this, please let me know. Thanks.
Convert all first character in an email id to Upper case in BASH
bash
You can actually do this entirely in Bash, without any external commands, using word splitting and parameter expansion. It's even fairly short:EMAIL_ADDRESS=this.is.a.very-long_email.id@domainname.comUSER=${EMAIL_ADDRESS%@*}WORDS=( $(IFS=._- ; printf '%s ' $USER) )echo ${WORDS[@]^}I'll take this line-by-line:USER=${EMAIL_ADDRESS%@*}This sets the USER variable to the part of EMAIL_ADDRESS that doesn't match @* at the end - that is, removing the domain name and leaving only the user part of the address.WORDS=( $(IFS=._- ; printf '%s ' $USER) )This creates an initialises an array WORDS. The initial values are given by the results of command substitution $(...).Command substitutions run in a subshell, so we can change the values of variables safely without affecting their values in our main shell. That includes IFS, which is used during word splitting as the group of characters that cause a new word to begin. Each one of ., _, and - will form a word boundary, and you can add new characters there if you wish.After changing IFS we use printf to print out the words $USER has been split into, which is a little safer than echo.echo ${WORDS[@]^}Finally, we print out the result. The [@] is array expansion, as you know, and then ^ performs upper-casing of the first character in the word (strictly, the first match of the default pattern ?).The final result of running this script is the output:This Is A Very Long Email Idas expected.If any email addresses contain shell metacharacters *, ?, etc, they will be expanded as wildcards. You can wrap the WORDS= line in set -f / set +f to avoid that, but there's another option (courtesy of Glenn Jackman in the comments).IFS=._- read -r -a WORDS <<<${EMAIL_ADDRESS%@*}echo ${WORDS[@]^}This uses read -a to populate an array with the results of word splitting, and the rest (condensed) as before. I find this less clear to read than the explicit array initialisation, but it's an option.It's also worth noting that email addresses can strictly have a wide variety of forms, including ones with spaces, quotes, and bracket characters in them, and this doesn't deal with those addresses at all (nor is it really possible to do so given your problem specification).