Score:2

apt-cache show - show single field of a package

it flag

As for:

$ dpkg -f <deb-file> <field>

there is something that likewise:

$ apt-cache show <package> <field>

returns me a field of a package?

For example, assuming I have discord already installed and its .deb archive in the current directory, I run the commands:

$ dpkg -f ./discord.deb Version
$ apt-cache show discord Version

Outputs I'd like:

0.0.27
0.0.27

Actual output:

0.0.27
... # discord package unwanted long output
N: Unable to locate package Version

I'd like a solution that makes use of the apt-cache or dpkg command itself.
In the absence of such a solution, then I accept the usual parser.

How do I solve?

EDIT 1:

I only want to display the installed version of a package.

Raffa avatar
jp flag
`apt-cache show` takes only package-names as arguments ... So, `Version` will be looked up as a package.
Score:2
vn flag

To show only the installed version of a package: (and subsequently, this only works for installed packages)

dpkg-query --showformat='${Version}' --show <package>

To include a line break, just include a newline in the format string:

dpkg-query --showformat='${Version}\n' --show <package>
Raffa avatar
jp flag
`--showformat=` accepts "\" as an escape character ... So, `--showformat='${Version}\n'` should work to feed a newline after the output.
it flag
Yes, you are right, "apt-cache show" would also show the version of a package not yet installed, which is not what I want. Thanks for pointing it out to me.
it flag
This is the solution I want, thank you.
it flag
For line break also this `dpkg-query -f '${Version}\n' -W <package>` is good.
Score:2
br flag

This one-liner extracts the version of a package:

apt-cache show packagename | awk '/^Version:/{print $2;}'
Raffa avatar
jp flag
Some packages might show more than once in the output like e.g. apt and dpkg ... So, to print only the first reported version an `exit` action might be added like e.g. `apt-cache show apt | awk '/^Version:/{print $2; exit}'`
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.