Edit: Please note, as written below, I'm aware of answers on this site explaining that apt-get
uses regex to interpret packages' names. In fact, the question is directly about a way in which its actual behavior is different from that documented one. Please read the question before suggesting a duplicate.
Some answers on this site warn about using apt-get
with wildcards (i.e., asterisks: *
), because apt-get
supposedly expands them as regular expressions, which might give unexpected (and undesired) results, especially with apt-get remove
. Indeed, Ubuntu man
page for apt-get
reads:
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.
In fact, this answer claims:
apt-get accepts a regular expression and not a glob pattern as the shell.
I believe this is wrong (at least as of Xenial). For example, I can reproduce the following behavior:
$ sudo apt-get install -s 'meld*'
[...]
Note, selecting 'meld' for glob 'meld*'
[...]
$ sudo apt-get install -s 'meldt*'
[...]
Note, selecting 'python-meld3' for regex 'meldt*'
Note, selecting 'python3-meld3' for regex 'meldt*'
Note, selecting 'meld' for regex 'meldt*'
[...]
(I didn't remove any matches, only irrelevant parts of apt-get
's response.)
It would seem to me, based on this behavior, that apt-get
first attempts to match given expressions as globs, and only if it fails, will it then retry as regular expressions.
Do I have that right? Have I misunderstood the man
page, or is this behavior badly documented?
t*
match3
as a glob? as a regex, it matches as "zero or more instances oft
" (followed by anything, since the expression isn't anchored - compare tomeldt*$
) – steeldriver Jun 14 '17 at 15:44sudo apt-get install -s 'meld*'
(I get 100s of regex matches). What version of apt do you have? – Joe P Jun 14 '17 at 15:44t*
match is only regexes in the question – Joe P Jun 14 '17 at 15:47meld*
matches some packages (namely,meld
),apt-get
never notices that the regexmeld*
will also match (a substring of)python-meld3
. Butmeldt*
matches nothing as a glob, which is whyapt-get
interprets it as regex, finding the other two packages. – Jonathan Y. Jun 14 '17 at 15:47apt 1.2.20 (amd64)
. But I suspect the difference might be caused by my having enabled repositories which you haven't.meld 3.14.2-1
is inuniverse
. – Jonathan Y. Jun 14 '17 at 15:52apt 1.0.1ubuntu2 for amd64
. ... So it is an undocumented change in behaviour. – Joe P Jun 14 '17 at 15:56filea
,fileb
, andfilec
, then Bash expandsapt-get install file*
toapt-get install filea fileb filec
. You probably never want that, so it would be advisable to always quote-protect your globs and regular expressions from Bash expansions, such asapt-get install 'file*'
. The behavior ofapt-get
you have found is strange and interesting though ... – takatakatek Jun 14 '17 at 16:29apt-get install -s 'meld*' | cat
doesn't print the message about selecting for glob. – takatakatek Jun 14 '17 at 16:51man 5 apt_preferences | grep -1n glob
reveals that globbing is known to Apt in general, but I still think this is a documentation bug. It isn't for Ubuntu though, it is for the maintainers of Apt, Debian. – takatakatek Jun 14 '17 at 17:07'meld*'
and'meldt*'
in the same fashion. – Jonathan Y. Jun 14 '17 at 18:23