Leap year in linux

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












Can I know how to show a leap year between 2014-2020 in a Linux terminal?



Is there any way using some code like $cal - anything to show which year is leap year between 2014-2020 straightaway?










share|improve this question









New contributor




lee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 3




    stackoverflow.com/questions/32196628/…
    – Rinzwind
    2 hours ago














up vote
1
down vote

favorite












Can I know how to show a leap year between 2014-2020 in a Linux terminal?



Is there any way using some code like $cal - anything to show which year is leap year between 2014-2020 straightaway?










share|improve this question









New contributor




lee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 3




    stackoverflow.com/questions/32196628/…
    – Rinzwind
    2 hours ago












up vote
1
down vote

favorite









up vote
1
down vote

favorite











Can I know how to show a leap year between 2014-2020 in a Linux terminal?



Is there any way using some code like $cal - anything to show which year is leap year between 2014-2020 straightaway?










share|improve this question









New contributor




lee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











Can I know how to show a leap year between 2014-2020 in a Linux terminal?



Is there any way using some code like $cal - anything to show which year is leap year between 2014-2020 straightaway?







command-line






share|improve this question









New contributor




lee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




lee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 hours ago









Yufenyuy Veyeh Dider

921823




921823






New contributor




lee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 hours ago









lee

61




61




New contributor




lee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





lee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






lee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







  • 3




    stackoverflow.com/questions/32196628/…
    – Rinzwind
    2 hours ago












  • 3




    stackoverflow.com/questions/32196628/…
    – Rinzwind
    2 hours ago







3




3




stackoverflow.com/questions/32196628/…
– Rinzwind
2 hours ago




stackoverflow.com/questions/32196628/…
– Rinzwind
2 hours ago










1 Answer
1






active

oldest

votes

















up vote
3
down vote













You can make use of date's exit code to check for a leap year, relying on date's behaviour of generating a non 0 exit code for an invalid date, obviosuly there's no 29th of Feb in a non-leap year:



date -d $year-02-29 &>/dev/null
echo $?


as a function:



isleap() echo is not leap; 


Usage:



$ isleap 2019
is not leap

$ isleap 2020
is leap


Regarding your question:




Can i know how to show leap year between 2014-2020 in linux terminal?




echo "Leap years between 2014 and 2020:";
for y in 2014..2020; do
date -d $y-02-29 &>/dev/null && echo $y;
done





share|improve this answer






















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "89"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );






    lee is a new contributor. Be nice, and check out our Code of Conduct.









     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1081137%2fleap-year-in-linux%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    3
    down vote













    You can make use of date's exit code to check for a leap year, relying on date's behaviour of generating a non 0 exit code for an invalid date, obviosuly there's no 29th of Feb in a non-leap year:



    date -d $year-02-29 &>/dev/null
    echo $?


    as a function:



    isleap() echo is not leap; 


    Usage:



    $ isleap 2019
    is not leap

    $ isleap 2020
    is leap


    Regarding your question:




    Can i know how to show leap year between 2014-2020 in linux terminal?




    echo "Leap years between 2014 and 2020:";
    for y in 2014..2020; do
    date -d $y-02-29 &>/dev/null && echo $y;
    done





    share|improve this answer


























      up vote
      3
      down vote













      You can make use of date's exit code to check for a leap year, relying on date's behaviour of generating a non 0 exit code for an invalid date, obviosuly there's no 29th of Feb in a non-leap year:



      date -d $year-02-29 &>/dev/null
      echo $?


      as a function:



      isleap() echo is not leap; 


      Usage:



      $ isleap 2019
      is not leap

      $ isleap 2020
      is leap


      Regarding your question:




      Can i know how to show leap year between 2014-2020 in linux terminal?




      echo "Leap years between 2014 and 2020:";
      for y in 2014..2020; do
      date -d $y-02-29 &>/dev/null && echo $y;
      done





      share|improve this answer
























        up vote
        3
        down vote










        up vote
        3
        down vote









        You can make use of date's exit code to check for a leap year, relying on date's behaviour of generating a non 0 exit code for an invalid date, obviosuly there's no 29th of Feb in a non-leap year:



        date -d $year-02-29 &>/dev/null
        echo $?


        as a function:



        isleap() echo is not leap; 


        Usage:



        $ isleap 2019
        is not leap

        $ isleap 2020
        is leap


        Regarding your question:




        Can i know how to show leap year between 2014-2020 in linux terminal?




        echo "Leap years between 2014 and 2020:";
        for y in 2014..2020; do
        date -d $y-02-29 &>/dev/null && echo $y;
        done





        share|improve this answer














        You can make use of date's exit code to check for a leap year, relying on date's behaviour of generating a non 0 exit code for an invalid date, obviosuly there's no 29th of Feb in a non-leap year:



        date -d $year-02-29 &>/dev/null
        echo $?


        as a function:



        isleap() echo is not leap; 


        Usage:



        $ isleap 2019
        is not leap

        $ isleap 2020
        is leap


        Regarding your question:




        Can i know how to show leap year between 2014-2020 in linux terminal?




        echo "Leap years between 2014 and 2020:";
        for y in 2014..2020; do
        date -d $y-02-29 &>/dev/null && echo $y;
        done






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 2 hours ago









        Arronical

        12.7k84589




        12.7k84589










        answered 2 hours ago









        RoVo

        5,8691438




        5,8691438




















            lee is a new contributor. Be nice, and check out our Code of Conduct.









             

            draft saved


            draft discarded


















            lee is a new contributor. Be nice, and check out our Code of Conduct.












            lee is a new contributor. Be nice, and check out our Code of Conduct.











            lee is a new contributor. Be nice, and check out our Code of Conduct.













             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1081137%2fleap-year-in-linux%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            What does second last employer means? [closed]

            List of Gilmore Girls characters

            Confectionery