Scripting question

Jim Murphy friartek at stargate.chicago.il.us
Wed Nov 6 11:52:09 PST 2002


On Wed, Nov 06, 2002 at 01:08:51PM -0600, Archaic wrote:
> I needed to create a file with everyday of the year in mmddyy form.
> After searching some bash tutorials on the web I couldn't find an elegant
> way to construct the for loop, so I did the brute force method. Any
> suggestions? Here's my script (effective, but horrendous). 

Ok, so it's not bash, but it's one of the reasons I like zsh.

------

#! /bin/zsh

# make sure there are 2 digits(add leading 0 if needed)
typeset -Z2 mo day yr

yr=2

for (( m=1; m <= 12; m++ ))
do
        mo=${m}

        case ${m} in
                1|3|5|7|8|10|12)
                        maxday=31
                ;;
                4|6|9|11)
                        maxday=30
                ;;
                2)
                        # need some leap year code here
                        maxday=28
                ;;
        esac

        for (( d=1; d <= maxday; d++ ))
        do
                day=${d}
                print ${mo}${day}${yr}
        done
done

------

For what it's worth.

Jim

-- 
Jim Murphy
email: friartek at stargate.chicago.il.us
Linux - Debian/FloppyFW/LFS/RedHat

-- 
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