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
Post a Comment