[Smaug] A quick scripting puzzle

Thomas Leavitt thomas at thomasleavitt.org
Sat Nov 19 02:16:17 PST 2005

On Fri, 2005-11-18 at 08:43 -0800, smaug-request at lists.svlug.org wrote:
> Message: 2
> Date: Thu, 17 Nov 2005 20:26:33 -0800
> From: Peter Belew <peterbe at sonic.net>
> Subject: [Smaug] A quick scripting puzzle
> To: SMAUG Users <smaug at lists.svlug.org>
> Message-ID: <20051118042633.GA6844 at sonic.net>
> Content-Type: text/plain; charset=us-ascii
> For amusement, create a 1-line sh or bash command which will set
> a shell variable $LASTSUNDAY to the date (2-digit day) of the last
> Sunday in the current month.
> Like
>    LASTSUNDAY=`some_shell_stuff`
> Use only standard Unix utilities such as 'cat' or 'head' or 'date'.
> The command shouldn't take longer than an 80-character line.
> (I did this myself for creating a cron job which sends out email
> announcing a meeting on the last sunday of a month).
> :)
>  Peter

Here's my entry... I'm pretty sure, somewhere within the byzantine array
of options available in gcal, there's a way to directly produce this...
but I couldn't find it. However, this works, no matter whether there are
four or five Sundays in a month.

LASTSUNDAY=`gcal -i -s1|tail -n1|sed "s/[ ]*$//"|rev|cut -b-2|rev`

I'm not sure how this works, but you could probably cheat more, by
feeding gcal instructions to use some of these commands from a file...

and of course, I'm cheating, by using gcal, but hey. :)


More information about the Smaug mailing list