[X-Unix] shell script to determine 1st business day of month ?

Robar Philip philip.robar at gmail.com
Wed May 7 12:27:56 PDT 2008


On May 7, 2008, at 8:40 AM, Russell McGaha wrote:

> Do any of you know of a script callable from BASH, that will / can  
> say if today (or a given date) is the first business day of the month?

Here's my shot:

#!/usr/bin/env bash
#
# "The shebang line in this reworking of the script probably looks a  
little different than those
# you're used to seeing. The env command invokes the environment for  
bash, much as /usr/bin/bash
# would. However, this syntax avoids problems if the path to bash on  
your system is not /bin/bash."
# - http://open.itworld.com/5040/nlsunix070313/page_1.html
#
# firstworkday:
#
# Exit with true (0) if today is the first work day (Mon-Fri) of the  
month,
# otherwise exit with false (1).
#
# The first work day falls within the first three days of the month  
and if it's any day other
# than Monday it must be the first day of the month:
#
#	1st   2nd   3rd
#
#	Sat  Sun  Mon
#	Sun Mon ...
#	M-F ...
#
# So first check if today's date is not 1-3, if so then exit with  
false (1). Otherwise:
#
# If today is Monday then it must be the Month's first work day.
# If today is Tuesday-Friday and it's the 1st then today is the  
month's first work day.
#
# NOTE! This script does not take into account Holidays!

firstWorkDay=1			# Assume today is not the month's first work day.

dayOfWeek=$(date +%u)
monthDay=$(date +%d)

if [[ ${monthDay} -le 3 ]]; then
	case ${dayOfWeek} in
	  [1])		firstWorkDay=0;;
	  [2-5])	[[ ${monthDay} -eq 1 ]] && firstWorkDay=0;;
	esac
fi

exit ${firstWorkDay}



More information about the X-Unix mailing list