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


i modifying script reads in user email. simple, simple.

echo -n "please enter example.com email address: " read email email=${email%%@example.com} # removes trailing @example.com email echo "email $email" 

this works, lower case @example.com. how modify remove trailing @example.com, case insensitive?

if have bash 4:

email=${email,,} email=${email%%@example.com} 

otherwise, perhaps use tr:

email=$(echo "${email}" | tr "a-z" "a-z") email=${email%%@example.com} 

update:

if wanting strip host (any host) perhaps want:

email=${email%%@*} 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -