[ILUG] Bash script misbehaving
Niall O Broin
niall at magicgoeshere.com
Wed Aug 20 09:32:31 IST 2008
On 20 Aug 2008, at 09:16, Philip Reynolds wrote:\
> going slightly off your original topic, but there's code in your
> original
> post that looks like it'll be used for testing for the last day of
> the month
> as well. Hardcoding that might be ok if it wasn't for February 29th
> (which
> you've accounted for this year, but which obviously needs to be
> changed in
> the code for next February) ;)
>
> cal(1) can be used to calculate the last day of the current month with
> relative ease.
>
> /usr/bin/cal | awk '!/^$/{ print $NF }' | tail -1
>
> Simply test that value against
>
> date +'%d'
>
> Saves hardcoding those things :)
or more elegantly and efficiently, and we're all about elegance and
efficiency here :-), check for
date -d 'tomorrow' +'%d'
returning 1.
Of course this depends on Gnu date, but this is a Linux mailing list,
so no apologies there.
Niall
More information about the ILUG
mailing list