Can you explain why
This one gives $? = 1
echo "uus" | grep -w -o [0123456789]\*
and this one give $? = 0
echo "-uus" | grep -w -o [0123456789]\*
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.
Your regular expression can match an empty string. The
-wflag means that any match must be preceded by beginning-of-line or a non-word character, and followed by end-of-line or a non-word character.In the case of
uus, the beginning of line is followed be a word character, sogrepcan’t match an empty string as a word there. The end of line is preceded by a word character, sogrepcan’t match an empty string as a word there.In the case of
-uus, the beginning of line is followed by-, which is a non-word character, sogrepcan match the empty string as a word between the beginning of the line and the-character.