I am a shell script newbie. I want to know the difference between
${var%pattern}
and
${var%%pattern}
Thanks
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.
From
man bash:Here’s an example of what the difference is:
Notice that there are two possible matches for
def*at the end of$VAR: both “defabcdef” and just “def” match. With the “%” the shortest possible match for the patterndef*is deleted, so the trailing “def” is removed. With the “%%” the longest possible match is deleted, so “defabcdef” bites the dust.