[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: apt-get remove/purge with regex gives unexpected result



On Wed, 12 Feb 2014 18:04:49 +0100 Sven Joachim wrote:
>
> My interpretation of that paragraph is that apt-get first tries to
> interpret the pattern as a wildcard (see glob(7)) and only tries a
> regular expression match if the glob produces no matches.

Sven, it seems you are right. I tried the following commands:

$ sudo apt-get remove 'libre?f?ice.*'
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'libreoffice.org-calc' for regex 'libre?f?ice.*'
Note, selecting 'libreoffice.org-writer' for regex 'libre?f?ice.*'
Package 'libreoffice.org-calc' is not installed, so not removed
Package 'libreoffice.org-writer' is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 12 not upgraded.

$ sudo apt-get remove '^libre?f?ice.*'
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package ^libre?f?ice.*
E: Couldn't find any package by regex '^libre?f?ice.*'
E: Couldn't find any package by regex '^libre?f?ice.*'

The first command shows that libre?f?ice.* is treated as a glob
expression as it matched libreoffice.org-calc and
libreoffice.org-writer packages. It that expression ? means
"any single character".

The second command shows that ^libre?f?ice.* is treated as a regular
expression which didn't match the said packages because in regular
expressions "an atom followed by '?' matches a sequence of 0 or 1
matches of the atom."

I see a bug in the execution of the first command: it reports
  Note, selecting 'libreoffice.org-calc' for regex 'libre?f?ice.*'
but actually it should report
  Note, selecting 'libreoffice.org-calc' for glob expression 'libre?f?ice.*'

Definitely, apt-get manpage should be improved to clarify the usage of
glob expressions by default.

If I were the developer of apt-get I would provide an option for
changing the default treatment of pkg arguments as glob expressions to
regular expressions. It would prevent issues with regular expressions
that can be also valid glob expressions (as shown in my initial post).

-- rpr.


Reply to: