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

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)

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.