我在 !/bin/sh 中使用这样的代码:
LIST1="mazda toyota honda"
LIST2="2009 2006 2010"
for m in $LIST1
do
echo $m
done
如您所见,目前仅打印出汽车的品牌。 我如何根据相同的位置将年份包含在每个“echo ”中,以便获得如下结果:
马自达 2009
丰田 2006
本田 2010
?
最佳答案
假设 bash
array1=(mazda toyota honda)
array2=(2009 2006 2010)
for index in ${!array1[*]}
do
printf "%s %s\n" ${array1[$index]} ${array2[$index]}
done
关于shell - 如何在 unix shell 中使用数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1813640/