You are not logged in.

#1 2018-04-21 11:48:59

karcher
Member
Registered: 2018-01-09
Posts: 140

[SOLVED] Searching for exact package name

Hi all,

I want to search the sync DB for an exact package name. According to the wiki:
https://wiki.archlinux.org/index.php/Pa … _databases
pacman supports ERE (Extended Regular Expressions). But why when I enter:

$ sudo pacman -Ssq '^vim$'

the output includes "gvim", not only "vim"? As if the anchor "^" does not work. Why is that?

Last edited by karcher (2018-04-21 19:08:15)

Offline

#2 2018-04-21 12:22:19

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,529
Website

Re: [SOLVED] Searching for exact package name

If you know the exact name, why are you searching?  Just use the name, e.g. for package information do `pacman -Si vim`, to install it `pacman -S vim`.

EDIT: Regexes do work, but I gather the search also includes 'provides' as gvim provide vim, you'll note that the result for '^vim$' is much shorter than 'vim$'

Last edited by Trilby (2018-04-21 12:31:40)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2018-04-21 15:31:37

karcher
Member
Registered: 2018-01-09
Posts: 140

Re: [SOLVED] Searching for exact package name

@Trilby: thanks for the quick response!

"If you know the exact name, why are you searching?  Just use the name, e.g. for package information do `pacman -Si vim`, to install it `pacman -S vim`."

I want to use it within a script e.g. if a specific package in a list matches what exists in the sync DB. This is known to me.

"EDIT: Regexes do work, but I gather the search also includes 'provides' as gvim provide vim, you'll note that the result for '^vim$' is much shorter than 'vim$'"

It doesn't sound logical to me. When I have set the caret anchor I'm expecting to get only results starting with the character after that. Yes, the results are much more without the caret anchor.

So can I assume that there is not a way to get exactly one result?

EDIT:
Of course I could still use other commands to filter the results but I don't mean that.

Last edited by karcher (2018-04-21 15:50:28)

Offline

#4 2018-04-21 17:22:37

apg
Developer
Registered: 2012-11-10
Posts: 211

Re: [SOLVED] Searching for exact package name

pacsift --exact --name vim

Offline

#5 2018-04-21 17:23:56

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,529
Website

Re: [SOLVED] Searching for exact package name

karcher wrote:

I want to use it within a script e.g. if a specific package in a list matches what exists in the sync DB. This is known to me.

I don't really understand this.  If you know the exact package name, why are you searching for it?  What are you really trying to do with that script?

karcher wrote:

So can I assume that there is not a way to get exactly one result?

Yes, there is - if there is only one package that matches.  If there is more than one match, you'll get more than one result.  Either vim or gvim would satisfy the requirement of 'vim'.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#6 2018-04-21 19:04:08

karcher
Member
Registered: 2018-01-09
Posts: 140

Re: [SOLVED] Searching for exact package name

@apg:
Thanks for the hint! I've installed pacutils and with:
pacsift --sync --exact --name vim
I'm getting exactly one package.

@Trilby:
"I don't really understand this.  If you know the exact package name, why are you searching for it?  What are you really trying to do with that script?"

I have a list of packages that I normally install. Some of them are in the sync DB, some of them are in the AUR, some of them should be installed manually. I want to check if the package exists in the sync DB and then invoke pacman to install it etc. I had separated lists e.g. for pacman and AUR helper but I like it better when all packages are in one column.

"Yes, there is - if there is only one package that matches.  If there is more than one match, you'll get more than one result.  Either vim or gvim would satisfy the requirement of 'vim'."

But vim and gvim are different packages.

Offline

#7 2018-04-21 19:39:54

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,529
Website

Re: [SOLVED] Searching for exact package name

karcher wrote:

I have a list of packages that I normally install. Some of them are in the sync DB, some of them are in the AUR, some of them should be installed manually. I want to check if the package exists in the sync DB and then invoke pacman to install it etc.

But you still don't need to search.  Why loop through the list and use two pacman operations for each entry when one will do.  Instead of looping through the list and searching for each package then installing it if found, just attempt to install it, and on error append it to the aur list.  Or even better, instead of looping through the list and even calling pacman once for each entry, call pacman only twice overall:

pacman -Slq | sort > /tmp/repo.pkg
sort /path/to/yourlist > /tmp/needed.pkg
pacman -S $(comm -12 /tmp/repo.pkg /tmp/needed.pkg)
comm -13 /tmp/repo.pkg /tmp/needed.pkg | while read nonrepo; do
   # check aur for $nonrepo
done

"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#8 2018-04-21 19:50:37

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,390
Website

Re: [SOLVED] Searching for exact package name

pacman -Sql | grep "^vim$"

Offline

#9 2018-04-21 20:27:21

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,529
Website

Re: [SOLVED] Searching for exact package name

My first version is simpler:

pacman -S $pkg

If it succeeds, $pkg is in the repos, and now there is no need for an additional step of installing it.  If it fails, $pkg is not in the repos.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#10 2018-04-22 09:58:00

karcher
Member
Registered: 2018-01-09
Posts: 140

Re: [SOLVED] Searching for exact package name

Allan wrote:

pacman -Sql | grep "^vim$"

Thanks! With grep works fine but that I was meaning before without any other commands.

Trilby wrote:

But you still don't need to search.  Why loop through the list and use two pacman operations for each entry when one will do.  Instead of looping through the list and searching for each package then installing it if found, just attempt to install it, and on error append it to the aur list.  Or even better, instead of looping through the list and even calling pacman once for each entry, call pacman only twice overall

It seemed to me cleaner. Thanks for the code. I think, I will use it.

Trilby wrote:

My first version is simpler:

pacman -S $pkg

If it succeeds, $pkg is in the repos, and now there is no need for an additional step of installing it.  If it fails, $pkg is not in the repos.

Right!

Offline

Board footer

Powered by FluxBB