Bash scripting, how to remove trailing substring, case insensitive?

I am modifying a script that reads in a user email. It is very simple, too simple.

echo -n "Please enter your email address: "
read email
email=${} # removes trailing from email
echo "email is $email"

This works, but only for lower case How could I modify this to remove the trailing, case insensitive?


If you have bash 4:


Otherwise, perhaps just use tr:

email=$(echo "${email}" | tr "A-Z" "a-z")


If you are just wanting to strip the host (any host) then perhaps this is really what you want:


For Bash 3.2 and greater:

shopt -s nocasematch
[[ $email =~ $pattern ]]
email=${BASH_REMATCH[1]}    # result: JoHnDoE

Need Your Help

.NET attributes in shipping assemblies fxcop

c# .net fxcop

I wonder if people (meaning the company/developers) really care about having [SuppressMessage] attributes lying around in the shipping assemblies.

C# continue in one line ForEach

c# foreach continue

Why I can't do that ? How to manipulate code ?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.