Why does regex rpm -qi rpm-build | grep -E [[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+$
return
? Isn't the regex supposed to match periods with \.
? If so why is not the first match the only one returned ?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityYou haven't quoted the regular expression, so your shell processed the two backslashes. As a result, grep
saw this regular expression: [[:digit:]]+.[[:digit:]]+.[[:digit:]]+$
which indeed matches. Quote the expression:
rpm -qi rpm-build | grep -E '[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+$'
If you really just want the version information from rpm -q
, ask for it directly with --queryformat
, and skip the grep:
version=$(rpm -q --queryformat '%{VERSION}' rpm-build)
*
or $
, etc. The shell doesn't particularly care about plain periods here, so yes, it strips/processes the backslash before handing it all over to grep
.
sed
workaround:rpm -qi rpm-build | grep Version | sed 's/Version\s+:\s+//'