我明白那个:
$ apt-cache search package_name
将搜索名称和说明中的匹配项。
但是,这是如何工作的呢?
$ apt-cache search package_name$
例如,
$ apt-cache search desktop
将产生名称或描述中名称随处带有“桌面”的软件包的名称和简短描述的列表。
然后,如果我理解正确,
$ apt-cache search desktop$
应该产生一个子集,其中“桌面”是名称中或描述中任何一行中的最后一个词。
但是我发现了一个示例,即使根据的描述在描述的倒数第二行中有“桌面” xjig
,也显示,apt-cache search desktop
但没有显示:apt-cache search desktop$
apt-cache show xjig
Description-zh:X11拼图游戏
xjig是一种尝试尽可能在屏幕上复制拼图游戏的拼图
。可以加载任何GIF,JPEG或PPM图像并将其切成
小块。目标(与任何拼图游戏一样)是重新组合
原始图片。
。
可以使用鼠标自由旋转瓷砖,翻转瓷砖(用于
双面拼图),甚至可以在桌面上显示为成形的窗口
(建议为后者使用快速的机器/视频卡!)。
在/ usr / share / games / xjig中提供了一个示例图像。
那么为什么xjig
不包含在输出中apt-cache search desktop$
呢?
从apt-cache
手册页:
search regex...
search performs a full text search on all available package lists for the
POSIX regex pattern given, see regex(7). It searches the package names
and the descriptions for an occurrence of the regular expression and
prints out the package name and the short description, including virtual
package names. If --full is given then output identical to show is
produced for each matched package, and if --names-only is given then the
long description is not searched, only the package name is.
Separate arguments can be used to specify multiple search patterns that
are and'ed together.
注意它指出regex(7)
。因此,当您告诉apt-cache
要搜索的内容时,便会为其提供正则表达式。将$
在正则表达式的手段,你要匹配,挂靠在字符串的结尾。
因此,如果给定值,desktop$
我们将只匹配字符串desktop
末尾的字符串,例如:
但它不会匹配以下字符串:
在您的情况下desktop
,xjig的描述中的字符串尽管在描述的一行末尾,但也不在描述字段的值的末尾。
这是xjig的描述。
Description-en: An X11 jigsaw puzzle
xjig is a puzzle that tries to replicate a jigsaw puzzle on the screen
as closely as possible. Any GIF, JPEG or PPM image may be loaded and cut
into pieces. The goal (as with any jigsaw puzzle) is to reassemble the
original picture.
.
Tiles may be freely rotated by use of the mouse, flipped (for
double-sided puzzles) and even shown as shaped windows on the desktop
(fast machine/video card recommended for the latter!). An example image
is provided in /usr/share/games/xjig .
如果我搜索以结尾的所有字符串xjig .$
。
$ apt-cache search 'xjig \.$'
xjig - An X11 jigsaw puzzle
请记住,描述的值只是一个长字符串,该字符串在此时被换行,因此尽管“ desktop”在一行的末尾,但实际上它不在描述值的末尾。
给定您要查找的单词,desktop
您可以查找在字符串的两边都带有空格(\s
)或单词边界(\b
)的字符串。
$ apt-cache search '\sdesktop\s' | grep xjig
xjig - An X11 jigsaw puzzle
$ apt-cache search '\bdesktop\b' | grep xjig
xjig - An X11 jigsaw puzzle
也许grep
用来查看锚在正则表达式中的作用会有所帮助。
台式机不在末尾
$ echo "this is a desktop string" | grep "desktop$"
$
桌面端
$ echo "this is a desktop" | grep "desktop$"
this is a desktop
将$
匹配锚定到字符串末尾的称谓是^
将匹配锚定到开头的称谓。
桌面不是开始
$ echo "this is a desktop" | grep "^desktop"
$
开始时是台式机
$ echo "desktop this is a desktop" | grep "^desktop"
desktop this is a desktop
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句