我有一个如下变量:
Variable1="PanicA0 PanicA1"
Variable2="PanicA0"
我必须比较 variable1 和 variable2 并且应该将输出回显为PanicA1
ie "PanicA1" is not in Varaiable2
。我如何使用 shell 脚本来实现这一点?
这是脚本
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
.
Variable1="PanicA0 PanicA1"
variable2="PanicA0"
varArr=($Variable1)
for word in "${varArr[@]}"
do
[[ $variable2 == *${word}* ]] || echo "$word is not in varaiable2"
done