如何使用bash脚本并排打印两个数组? [英] How to print two arrays side by side with bash script?

查看:21
本文介绍了如何使用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脚本并排打印两个数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆