united states of america usa  linkedinfacebook   Call Us Today: (315) 646-4455

Bash: determine if the week is odd or even


We regularly post scripts and script snippets that we have found useful in our day-to-day IT support tasks. Here's a quick way to help determine if the week is odd or even using a bash script. You can replace the echo "even" and "odd" with whatever functions you are looking to perform, such as weekly backups for example. Although not tested, this script should also work on any version of Apple's Mac.

Copy and paste this into a file:

WEEK=`date +"%V"`
if [ $(($WEEK%2)) -eq 0 ];
    echo "even";
    echo "odd";

ALT is a one-stop IT consulting company, servicing clients in Ottawa, Central New York and Syracuse, Miami and South Florida. Contact us for your IT support needs and our expert consultants will be happy to assist.

Original knowledge base article was posted on our Miami ALT Technical site.

Last updated Apr 13, 2024