Skip to content

Linux script to find last quarter

##find_last_quarter.sh
currentmonth=`date +’%m’`
##echo $currentmonth
currentyear=`date +’%Y’`
lastyear=`expr $currentyear – 1`

##echo $currentyear
##echo $lastyear

if [ $currentmonth = 01 ]; then
echo “Last Quarter was Q4 $lastyear”
elif [ $currentmonth = 02 ]; then
echo “Last Quarter was Q4 $lastyear”
elif [ $currentmonth = 03 ]; then
echo “Last Quarter was Q4 $lastyear”
elif [ $currentmonth = 04 ]; then
echo “Last Quarter was Q1 $currentyear”
elif [ $currentmonth = 05 ]; then
echo “Last Quarter was Q1 $currentyear”
elif [ $currentmonth = 06 ]; then
echo “Last Quarter was Q1 $currentyear”
elif [ $currentmonth = 07 ]; then
echo “Last Quarter was Q2 $currentyear”
elif [ $currentmonth = 08 ]; then
echo “Last Quarter was Q2 $currentyear”
elif [ $currentmonth = 09 ]; then
echo “Last Quarter was Q2 $currentyear”
elif [ $currentmonth = 10 ]; then
echo “Last Quarter was Q3 $currentyear”
elif [ $currentmonth = 11 ]; then
echo “Last Quarter was Q3 $currentyear”
elif [ $currentmonth = 12 ]; then
echo “Last Quarter was Q3 $currentyear”
else
echo “Error: check your script”
fi;