How to do "else" in bash case command?
bash
Solution
Solved with this `*)` so the whole code is:
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
Problem
``` 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 ``` I try running that script but it doesn't work, how should I display the `filter is on but the phone number doesn't match` part? I'm still learning, I know I can do it with `if else` statement but I wonder if I can do it with `case` too.