0

I'M trying to test a function that would be able to determine if it was or was not leap year. I believe my problem lies in the if statement but due to my lack of knowledge concerning shell I don't know what else to do here.

#! /bin/bash

read -p "Enter year" YY


leap_year()
{
    if [ (expr 0 -eq (${YY} % 4)) ] && [ (expr 0 -ne (${YY} % 100)) ]; then
        echo "Leap Year"

    else
        echo "Not leap Year"
    fi
}

leap_year $YY
2
Contributors
1
Reply
4
Views
4 Years
Discussion Span
Last Post by Watael
0

hi,

you're using test builtin operators inside expr expression.
expr is useless external command: bash can do arithmetic evaluation (see man bash /^ARITHMETIC EVALUATION)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.