2つの配列から重複している要素だけを取り出すスクリプトメモ
#!/bin/bash
array1=("hoge" "fuga" "foo" "bar" "barbar" "1" "hogehoge" "temp" "varvar")
array2=("varvar" "hoge" "fuga" "foo" "barbar" "2" "123" "tmp" "varvarvar" "1")
echo ${array1[@]}
echo ${array2[@]}
for p in ${array1[@]}; do
for q in ${array2[@]}; do
if [ "${p}" = "${q}" ]; then
array3+=(${p})
fi
done
done
echo ${array3[@]}
実行例
./arraycompare.sh
hoge fuga foo bar barbar 1 hogehoge temp varvar
varvar hoge fuga foo barbar 2 123 tmp varvarvar 1
hoge fuga foo barbar 1 varvar