Scripting question

Simon Geard delgarde at ihug.co.nz
Thu Nov 7 02:06:38 PST 2002


Jason Gurtz wrote:

> Wow, he wins in my book.  However "%a" should be "$a" and the output
> formatting needs help via sed:
> 
> #!/bin/bash
> for ((a=1;a<366;a++))
> do
>         date +%M%D%Y -d "Jan 01 + $a day" | \
>         sed s/^00//g | sed s/[0-9][0-9][0-9][0-9]$//g
> done
> 

Another catch is that it returns days from 02-Jan-2002 to 01-Jan-2003,
rather than 01-Jan-2002 to 31-Dec-2002. Nor am I clear what the need for
the sed command is - simply using the format %m%d%y should be all that's
required... A little adjustment for leap years has also been added...

# Get number of days in year (by checking if Feb29 exists)
if[ `date +%d -d "Feb 01 + 28 day"` = "29" ]
then
    days=366
else
    days=365
fi
# Iterate days
for ((a=0; a<$days;a++))
do
    date +%m%d%y -d "Jan 01 + $a day"
done


Does that help?

Simon
-- 
Unsubscribe: send email to listar at linuxfromscratch.org
and put 'unsubscribe blfs-support' in the subject header of the message



More information about the blfs-support mailing list