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

Re: aptitude or apt-get: how to use the jolly character?



Boyd Stephen Smith Jr. wrote:
In <[🔎] 878wkcdobs.fsf@gmail.com>, Rodolfo Medina wrote:
Suppose that I want to remove all the packages beginning with `texlive',
that are a lot in my system.

If I do: `aptitude purge texlive*', the system complains that no package
has that name.

Right, the shell performs "globbing", matching such patterns against pathnames and providing multiple arguments to the underlying command. As packages aren't accessible via pathnames, you can't count on your shell finding them.

How to do then?

Aptitude itself uses regular expressions (I like PCRE, might just be posix-
extended) to match against package properties paired with "atoms" or "operators" (I can't remember the correct terminology) to select which property or combine searches.

In this case use the aptitude search string "~n^texlive" or simply "^texlive" since "~n" is the default.

Since these aptitude search expressions can have characters in them that the shell interprets (e.g. *, ?, and [] all have special meaning in both regular expressions and shell "glob"s), you'll want to surround the expression in single-quotes to prevent the shell from interpreting it -- passing it directly to aptitude after removing the quotes.

Something like:
aptitude purge '^texlive'
Of course, things get really confusing when they have special meanings in both the shell and regexps, and you want to negate both of them. Suppose I want to grep for a letter (f in this example) followed by the asterisk in a file, I'd need to use this command:
grep f\\\* $file

grep f* $file would search for the name of any file in the current directory beginning with f, in that file (or the below if no files begin with f) grep f\* $file would search for 0 or more occurences of the letter f in that file (in other words, every line) grep f\\* $file would search for the name of any file in the current directory beginning with f\ in that file (or the below if no files begin with f\)
grep f\\\* $file would search for an f followed by an asterisk.

And that gets even more confusing when you put it in C, in, for example, a system() call:
system("grep f\\\\\\* $file");
(The backslashes are doubled up so that C does not interpret them as its own escape characters, like \n). And if you wanted (for example) a newline in the middle of that command, you would probably die from confusion :p

--
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/CM/IT d>++ s+:- a---- C+++ UL+++>++++ P+>+++ L+++>+++++ E---->--- W+++ N o? K? w--- O+ M-- V- PS PE? Y-- PGP- t+ 5? X- R-- tv+ b++ DI D G++ e- h! !r y ------END GEEK CODE BLOCK------


Reply to: