尝试从正确对齐的2个不同变量中打印出值列表.
foreach finalList ($correctList $wrongList)
printf "%20s%s\n" $finalList
end
Run Code Online (Sandbox Code Playgroud)
这将它们打印出来并且它们是对齐的,但它是一个接一个.我如何通过每个列表中的每个项目然后转到新行?
我希望他们最终看起来像这样:
Correct Incorrect
Good1 Bad1
Good2 Bad2
Good3 Bad3
Run Code Online (Sandbox Code Playgroud)
好来自correctList Bad来自wrongList
摆脱\n使它像这样:
Good1 Bad1 Good2 Bad2
Run Code Online (Sandbox Code Playgroud)
我只想要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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14957 次 |
| 最近记录: |