分享一个linux系统中采用嵌套for循环比较两个数组内容,并输出相同值的shell脚本
#!/bin/bash array1=(1 3 5 6 7 9) array2=(3 4 9) echo array1=${array1[@]} echo array2=${array2[@]} for i in ${array1[@]};do for j in ${array2[@]};do if [ $i -eq $j ];then echo -e "\033[32m same number is $i \033[0m" fi done done
No pain, no gain!