Cleaner method for this if-then statement?

I have a script that runs once per month. It performs a certain task ONLY if the month is January, April, July, or October.

MONTH=`date +%m`
if [ $MONTH -eq 1 ] || [ $MONTH -eq 4 ] || [ $MONTH -eq 7 ] || [ $MONTH -eq 10 ]; then
  do something
else
  do a different thing
fi

Is there a neater way of doing it than my four separate "or" comparisons? That seems like a lot of words just to check if month = 1,4,7,10.

Just curious. This is HP-UX 11.31 if it matters.

Thanks

An option:

$ cat DateTest
for month in 1 2 3 4 5 6 7 8 9 10 11 12; do
  if [ $((month%3-1)) -eq 0 ]; then
    echo Month is $month
  fi
done
$ ./DateTest
Month is 1
Month is 4
Month is 7
Month is 10
1 Like

Try case:

case $MONTH in
  1|4|7|10) do_something ;;
  *)        do a different thing
esac
2 Likes