gpt4 book ai didi

Unix C Shell 脚本 printf 帮助

转载 作者:行者123 更新时间:2023-12-04 16:18:03 26 4
gpt4 key购买 nike

尝试打印正确对齐的 2 个不同变量的值列表。

foreach finalList ($correctList $wrongList)
printf "%20s%s\n" $finalList
end

这会将它们打印出来并对齐,但它是一个接一个。我如何让它遍历每个列表中的每个项目,然后转到一个新行?

我希望它们最终看起来像这样:
Correct    Incorrect
Good1 Bad1
Good2 Bad2
Good3 Bad3

好来自正确列表
坏来自错误列表

摆脱\n 使它像这样:
Good1     Bad1    Good2    Bad2

我只想要 2 列。

最佳答案

您可以像这样同时迭代两个列表:

# Get the max index of the smallest list
set maxIndex = $#correctList
if ( $#wrongList < $#correctList ) then
set maxIndex = $#wrongList
endif

set index = 1
while ($index <= $maxIndex)
printf "%-20s %s\n" "$correctList[$index]" "$wrongList[$index]"
@ index++
end

关于Unix C Shell 脚本 printf 帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/267287/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com