For example, I have a string: test1@test2.
I need to get the test2 part of this string. How can I do this with bash?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Using Parameter Expansion:
#character says Remove the smallest prefix of the expansion matching the pattern.%character means Remove the smallest suffix of the expansion matching the pattern. (So you can do"${str%@*}"to get the"test1"part.)/character means Remove the smallest and first substring of the expansion matching the following pattern. Bash has it, but it’s not POSIX.If you double the pattern character it matches greedily.
##means Remove the largest prefix of the expansion matching the pattern.%%means Remove the largest suffix of the expansion matching the pattern.//means Remove all substrings of the expansion matching the pattern.