输入命令需要简单的脚本/循环/命令,在文本文件中执行和输出

Pan*_*dya 5 command-line scripts execute-command

假设我在文本文件中有如下命令列表 ( cat cmdlist.txt):-

cut
lshw
top
awk
sensors
Run Code Online (Sandbox Code Playgroud)

现在我想分别通过等获取有关该命令的简单信息whatis cutwhatis lshwwhatis <commadnd>在文本文件中打印这些输出说cmdinfo.txt

cmdinfo.txt( cat cmdinfo.txt) 的期望输出:-

cut (1)              - remove sections from each line of files
lshw (1)             - list hardware
top (1)              - display Linux processes
awk (1)              - pattern scanning and text processing language
sensors (1)          - print sensors information
Run Code Online (Sandbox Code Playgroud)

如何分别从 for 命令的cmdinfo.txt输出中获取文件?whatiscmdlist.txt

这只是示例txt 文件。

如果需要,建议简单的脚本。

Rad*_*anu 9

尽可能简单:

xargs whatis < cmdlist.txt > cmdinfo.txt
Run Code Online (Sandbox Code Playgroud)


Let*_*ety 5

更简单的一个,

$ while read -r line; do whatis "$line"; done < cmdlist.txt > cmdinfo.txt
cut (1)              - remove sections from each line of files
lshw (1)             - list hardware
top (1)              - display Linux processes
awk (1)              - pattern scanning and text processing language
sensors (1)          - print sensors information
Run Code Online (Sandbox Code Playgroud)

使用以下命令将结果写入文件。

while read -r line; do whatis "$line"; done < cmdlist.txt > cmdinfo.txt
Run Code Online (Sandbox Code Playgroud)