21 July 2024
Bash: determine if the week is odd or even

Bash: determine if the week is odd or even

21 July, 2024

bash

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:

#!/bin/bash
WEEK=`date +"%V"`
if [ $(($WEEK%2)) -eq 0 ];
then
    echo "even";
else
    echo "odd";
fi
ALT Technical

© ALT Technical. All rights reserved.