[Smaug] A quick scripting puzzle
Jay Campbell
jay at got.net
Thu Nov 17 21:13:01 PST 2005
You'd have to escape the backticks to use this inside the
LASTSUNDAY example backticks, and on re-parsing the question
it asked for the date, not just day-of-month, so you'd have
to tack more characters into the second `date`s format string.
So I'm over 80 characters anyway. The practice of shaving bytes
off code like this is called 'golfing' in some circles (i.e. perl)
j
> It took all 80.
>
> (for x in 1 2 3 4 5;do date -d"$x sun";done)|grep `date +%b`|tail -1|cut -c9-10
>
> This assumes a non-ancient version of `date` that understands
> '1 sunday', '2 sunday' to mean the next two sundays.
>
> j
>
> > 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
> >
> > --
> > My Web: http://www.armory.com/~peterbe/
> > News: http://www.sonic.net/~peterbe/news.html
> > Humor: http://www.ibiblio.org/Dave/this-week.html
> > Goat: http://www.livejournal.com/site/goat.bml
> > (I'm 'velikij' on LJ)
> >
> > _______________________________________________
> > Smaug mailing list
> > Smaug at lists.svlug.org
> > http://lists.svlug.org/lists/listinfo/smaug
> > Smaug home page: http://www.scruz.org/
> >
>
> --
>
> Jay Campbell
>
> _______________________________________________
> Smaug mailing list
> Smaug at lists.svlug.org
> http://lists.svlug.org/lists/listinfo/smaug
> Smaug home page: http://www.scruz.org/
>
--
Jay Campbell
More information about the Smaug
mailing list