Alister Kyle Alister Kyle - 1 month ago 8
Linux Question

Selecting strings and characters from variables in bash

I'm reading text in from a txt file, and I have to create a username from an email. The email address is in a single variable. The username must be the first letter of the users first name, and their entire last name. For example, joe.bloggs@gmail.com's username would be "jbloggs"

How do I select the first letter from the first name, then the entire last name, and concatenante them into 1 variable? I think I use the cut method but I'm unsure how to do it.

Thanks

Answer Source
mailbox=${EMAIL%@*}
echo ${mailbox:0:1}${mailbox#*.}

The first line removes the domain. The second grabs the initial and then removes the whole first name to leave the last.