cal -m | awk ‘{print $7}’ | grep -E ‘[0-9]’ | tail -n 1
returns:
28
NOTE: The cal command is run using the -m switch to have the first day of week to be Monday.
cal -m | awk ‘$7!=””{l=$7} END {print l}’