1

The question is about apt-cache commands other than search regex.

I know I can use a star character as a wildcard, for example apt-cache policy 'firefox*', but I could not find any documentation on what else is possible. Is it the same as filename expansion? Does something like extglob switch exist for it?

The actual problem i'm trying to solve is to have apt-cache policy show me everything 'firefox*' except all the -l10n- packages.

0

Package names are handled as described in the documentation for apt-get install (yes, it’s not obvious):

If no package matches the given expression and the expression contains one of '.', '?' or '*' then it is assumed to be a POSIX regular expression, and it is applied to all package names in the database. Any matches are then installed (or removed). Note that matching is done by substring so 'lo.*' matches 'how-lo' and 'lowest'. If this is undesired, anchor the regular expression with a '^' or '$' character, or create a more specific regular expression.

Strictly speaking, this check comes after a glob performed on the available package names — so package specifications are first checked for an exact match, then checked for glob matches (using ? and *), and if that doesn’t find anything, and the package specification contains ., ?, or *, interpreted as regular expressions. (You can see the globbing behaviour by running apt-cache policy 'firefo?', which matches using only a glob, and then apt-cache policy 'firefox?', which ends up using a regular expression.)

apt-cache policy 'firefox*' matches using globs. If you want to force it to match using a regular expression, you can use something like apt-cache policy 'firefox.*' instead; check for mozilla-firefox in the output to see if the expression is matched as a glob or as a regular expression.

apt-cache search is documented explicitly as handling regular expressions because its arguments are always treated as regular expressions.

Given the kind of regular expressions apt supports, excluding -l10n- is probably impossible; see this SO answer for details.

5
  • If pkg can be interpreted as RE, then why does documentation (man apt-cache) distinguish between search (search regex...) and all other commands (e.g. policy [pkg...])? – ultracrepidarian Mar 18 '19 at 8:14
  • Regarding -l10n-, I do see them as well. I don't want to see them. And I'm already single-quoting the name, 'firefox*'. – ultracrepidarian Mar 18 '19 at 8:17
  • Oh, I had misunderstood, sorry. See my update. – Stephen Kitt Mar 18 '19 at 8:35
  • Would this not be a 100% correct way to exclude packages containing l10n: apt-cache policy 'firefox([^l]|l[^1]|l1[^0]|l10[^n])*$'? – ultracrepidarian Mar 18 '19 at 9:18
  • No, that also excludes packages ending with l, such as firefox-certificatepatrol, firefox-form-history-control... – Stephen Kitt Mar 18 '19 at 9:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.