lewashby 56 Junior Poster

Below is a program I'M trying to write that will take an 8 digit date and validate whether or not it's a valid date. I'M very new to shell scripting so I really a have no idea what I'M going. Could you take a look and let me know what all I'M doing wrong here? Thanks.

#! /bin/bash -x

# This is the calender array for the DateValidation program
CALENDER=(31 28 31 30 31 30 31 31 30 31 30 31)

read -p "Enter a date for validation: " DATE

# establish the varible LEN to hold the number of characters in Date, 8 is the only valid number
LEN=$(echo ${#DATE})

if [ $LEN -eq 8 ]; then #{

    # set date dariables MM, DD, & YY
    export MM=${DATE:0:2}
    export DD=${DATE:2:2}
    export YY=${DATE:4:4}

    if [ ${YY} -gt 0 ]; then #{
        if [ ${MM} -gt 0 & < 13 ]; then #{
            if [ ${MM} -eq 2 ]; then #{
                if [ is_leap_year ${YY} == 1 ]; then #{
                    if [ ${DD} -gt 0 & -le 29 ]; then #{
            elif [ ${DATE} -gt 0 & -le ${CALENDER[${MM}]}] #}}}}}}

    echo "${DATE} is a valid date"
else
    "${DATE} is an invalid date"
fi #}

#############################
### FUNCTION-is_leap_year ###
#############################

is_leap_year() {

if [ 0 -eg ${YY} % 4 & 0 -ne {YY} % 100 or 0 -eq ${YY} % 400 ]; then #{

    return true #}
else #{
    return false #}

exit
#END
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.