本文介绍了如何与bash脚本并排打印两个数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
无论是在Google还是在stackoverflow上,我都找不到这个问题的简单好答案.
I couldn't find a good and simple answer to this question neither on google nor here on stackoverflow.
基本上,我需要两个数组并排打印到终端中,因为一个数组是术语的列表,另一个是术语的定义.有人知道这样做的好方法吗?
Basically I have two arrays that I need to print into the terminal side by side since one array is a list of terms and the other the terms's definitions. Does anyone know a good way of doing this?
谢谢.
推荐答案
您可以使用C样式的for循环来完成此操作,假设两个数组的长度相同:
You can use a C-style for loop to accomplish this, assuming both arrays are the same length:
for ((i=0; i<=${#arr1[@]}; i++)); do
printf '%s %s\n' "${arr1[i]}" "${arr2[i]}"
done
这篇关于如何与bash脚本并排打印两个数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!