I am trying to check if a variable matches a regex in POSIX shell. However, this seems more difficult than I thought. I am trying to check if the variable is a valid size string (e.g. 10M or 6G etc)
if echo $var | grep -Eq '^\d+[MG]$'; then echo "match" else echo "no match" fi
That's what I tried, but for some reason I never get a match, even if the variable contains the correct string? Any idea why?