我有一个如下变量:
Variable1="PanicA0 PanicA1"
Variable2="PanicA0"
我必须比较variable1和variable2,并且应该将输出回显为PanicA1
,即"PanicA1" is not in Varaiable2
。我如何使用shell脚本实现这一目标?
答案 0 :(得分:0)
Variable1="PanicA0 PanicA1"
variable2="PanicA0"
varArr=($Variable1)
for word in "${varArr[@]}"
do
[[ $variable2 == *${word}* ]] || echo "$word is not in varaiable2"
done
答案 1 :(得分:0)
这是脚本
varone=`echo "PanicA0 PanicA1" | cut -d' ' -f1-`
vartwo=`echo "PanicA0" | cut -d' ' -f1-`
for i in $varone; do
for j in $vartwo; do
if [[ $i = $j ]]; then
echo "Matched: $i"
break
else
echo "$i is not in vartwo"
fi
done
done