使用this file,我想打印一个 包的依赖关系树,给定一个基本包。例如,拿 bash包打印程序包依赖关系树
@ bash
# few lines removed
requires: coreutils libintl8 libncursesw10 libreadline7 _update-info-dir cygwin
我想所需 包find-like输出部分例如
bash
bash coreutils
bash coreutils libattr1
bash coreutils libattr1 libintl8
bash coreutils libattr1 libintl8 libiconv2
bash coreutils libattr1 libintl8 _autorebase
bash coreutils libattr1 libintl8 _autorebase rebase
bash coreutils libattr1 libintl8 _autorebase rebase dash
bash coreutils libattr1 libintl8 _autorebase rebase dash cygwin
bash coreutils libattr1 libintl8 _autorebase rebase dash cygwin base-cygwin
我有这样的命令,但它不会递归
#!awk -f
$1 == "@" {
pkg = $2
}
$1 == "requires:" {
for (i=2; i<=NF; i++)
reqs[pkg][i-1] = $i
}
END {
query = "bash"
for (pkg in reqs[query]) {
print reqs[query][pkg]
}
}
我将开始与BEGIN {RS = “@”; FS = “\ n”}和比较$ i到 “要求:” 凡$ a1将是使用的名称在你的关联数组和某个字段中(使用for循环或其他)将以require - 使用substr在“:”之前移除并将其作为值存储....然后在END中,将使用关联数组递归地打印值 - 但要注意循环依赖关系 – technosaurus