filter="yes"
phonenumbers=(123 456 789 987 654 321)
echo "checking inbox now..."
myphonenumber=(7892)
if [[ "$filter" == "yes" ]]; then
case "${phonenumbers[@]}" in
*"$myphonenumber"*) echo "filter is on, phone number matches"
;;
!="$myphonenumber") echo "filter is on but the phone number doesn't match"
;;
esac
fi
if [[ "$filter" == "no" ]]; then
echo "filter off"
fi
我尝试运行该脚本但它不起作用,我该如何显示filter is on but the phone number doesn't match
部分?我还在学习,我知道我可以用if else
语句来做,但我想知道我是否可以用case
来做。
答案 0 :(得分:3)
解决了这个*)
所以整个代码是:
filter="yes"
phonenumbers=(123 456 789 987 654 321)
echo "checking inbox now..."
myphonenumber=(7892)
if [[ "$filter" == "yes" ]]; then
case "${phonenumbers[@]}" in
*"$myphonenumber"*) echo "filter is on, phone number matches" ;;
*) echo "filter is on but the phone number doesn't match" ;;
esac
fi
if [[ "$filter" == "no" ]]; then
echo "filter off"
fi