“while”命令循环次数过多

问题描述 投票:0回答:0

在“while”bash 命令中多次运行一个命令。

我正在使用适用于 Linux 的 Windows 子系统 (WSL) 具有以下 Ubuntu:

经销商编号:Ubuntu 描述:Ubuntu 20.04.4 LTS 发布:20.04 代号:焦点

我有一个文件 packages.txt 包含一些安装包的列表,比如:

zerofree
accountsservice
libtiff5
xserver-common
zlib1g
wslu
tar

我正在浏览它的每一行并使用以下命令为每一行运行“apt-cache show”:

$ while read p; do apt-cache show "$p"|grep -P 'Description-en' ; done < u

但是匹配的行显示不止一次,如下图:

Description-en: zero free blocks from ext2, ext3 and ext4 file-systems                                                  Description-en: query and manipulate user account information                                                           Description-en: query and manipulate user account information                                                           Description-en: Tag Image File Format (TIFF) library                                                                    Description-en: Tag Image File Format (TIFF) library                                                                    Description-en: common files used by various X servers                                                                  Description-en: common files used by various X servers                                                                  Description-en: common files used by various X servers                                                                  Description-en: compression library - runtime                                                                           Description-en: compression library - runtime                                                                           Description-en: compression library - runtime                                                                           Description-en: collection of utilities for the Windows 10 Linux Subsystem                                              Description-en: collection of utilities for the Windows 10 Linux Subsystem                                              Description-en: GNU version of the tar archiving utility                                                                Description-en: GNU version of the tar archiving utility

知道发生了什么吗?

bash shell while-loop grep apt
© www.soinside.com 2019 - 2024. All rights reserved.