Counting program fails in arithmetic test

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











up vote
0
down vote

favorite
1












having a little trouble with this rather basic script. This script works on Bash in my macbook pro, but not on my Linux Mint desktop, which also uses bash.



I can't figure out what's wrong with it.



I'm still getting an error from bash saying:



line 6: [: -lt: unary operator expected
line 16: [: -gt: unary operator expected


with this updated code:



#!/bin/bash
clear
counter=0

function countup
while [ $counter -lt 500 ]
do
((counter++))
echo $counter
sleep 0.2
done
countdown


function countdown
while [ $counter -gt 0 ]
do
((counter--))
echo $counter
sleep 0.2
done
countup


countup









share|improve this question



















  • 2




    add space after 0 => 0 ] and remove : in both functions
    – Costas
    Apr 11 '15 at 16:25






  • 1




    Take a look at: shellcheck.net
    – Cyrus
    Apr 11 '15 at 16:25










  • Shellcheck says it is all looking good, but I still get the error.
    – CYQ00000A
    Apr 11 '15 at 16:50






  • 2




    Works for me. Have you really posted the code you're running? Seems like $counter is empty in your real code (use "$counter").
    – choroba
    Apr 11 '15 at 16:53














up vote
0
down vote

favorite
1












having a little trouble with this rather basic script. This script works on Bash in my macbook pro, but not on my Linux Mint desktop, which also uses bash.



I can't figure out what's wrong with it.



I'm still getting an error from bash saying:



line 6: [: -lt: unary operator expected
line 16: [: -gt: unary operator expected


with this updated code:



#!/bin/bash
clear
counter=0

function countup
while [ $counter -lt 500 ]
do
((counter++))
echo $counter
sleep 0.2
done
countdown


function countdown
while [ $counter -gt 0 ]
do
((counter--))
echo $counter
sleep 0.2
done
countup


countup









share|improve this question



















  • 2




    add space after 0 => 0 ] and remove : in both functions
    – Costas
    Apr 11 '15 at 16:25






  • 1




    Take a look at: shellcheck.net
    – Cyrus
    Apr 11 '15 at 16:25










  • Shellcheck says it is all looking good, but I still get the error.
    – CYQ00000A
    Apr 11 '15 at 16:50






  • 2




    Works for me. Have you really posted the code you're running? Seems like $counter is empty in your real code (use "$counter").
    – choroba
    Apr 11 '15 at 16:53












up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





having a little trouble with this rather basic script. This script works on Bash in my macbook pro, but not on my Linux Mint desktop, which also uses bash.



I can't figure out what's wrong with it.



I'm still getting an error from bash saying:



line 6: [: -lt: unary operator expected
line 16: [: -gt: unary operator expected


with this updated code:



#!/bin/bash
clear
counter=0

function countup
while [ $counter -lt 500 ]
do
((counter++))
echo $counter
sleep 0.2
done
countdown


function countdown
while [ $counter -gt 0 ]
do
((counter--))
echo $counter
sleep 0.2
done
countup


countup









share|improve this question















having a little trouble with this rather basic script. This script works on Bash in my macbook pro, but not on my Linux Mint desktop, which also uses bash.



I can't figure out what's wrong with it.



I'm still getting an error from bash saying:



line 6: [: -lt: unary operator expected
line 16: [: -gt: unary operator expected


with this updated code:



#!/bin/bash
clear
counter=0

function countup
while [ $counter -lt 500 ]
do
((counter++))
echo $counter
sleep 0.2
done
countdown


function countdown
while [ $counter -gt 0 ]
do
((counter--))
echo $counter
sleep 0.2
done
countup


countup






bash shell shell-script






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 32 mins ago









Rui F Ribeiro

37.3k1374118




37.3k1374118










asked Apr 11 '15 at 16:19









CYQ00000A

75




75







  • 2




    add space after 0 => 0 ] and remove : in both functions
    – Costas
    Apr 11 '15 at 16:25






  • 1




    Take a look at: shellcheck.net
    – Cyrus
    Apr 11 '15 at 16:25










  • Shellcheck says it is all looking good, but I still get the error.
    – CYQ00000A
    Apr 11 '15 at 16:50






  • 2




    Works for me. Have you really posted the code you're running? Seems like $counter is empty in your real code (use "$counter").
    – choroba
    Apr 11 '15 at 16:53












  • 2




    add space after 0 => 0 ] and remove : in both functions
    – Costas
    Apr 11 '15 at 16:25






  • 1




    Take a look at: shellcheck.net
    – Cyrus
    Apr 11 '15 at 16:25










  • Shellcheck says it is all looking good, but I still get the error.
    – CYQ00000A
    Apr 11 '15 at 16:50






  • 2




    Works for me. Have you really posted the code you're running? Seems like $counter is empty in your real code (use "$counter").
    – choroba
    Apr 11 '15 at 16:53







2




2




add space after 0 => 0 ] and remove : in both functions
– Costas
Apr 11 '15 at 16:25




add space after 0 => 0 ] and remove : in both functions
– Costas
Apr 11 '15 at 16:25




1




1




Take a look at: shellcheck.net
– Cyrus
Apr 11 '15 at 16:25




Take a look at: shellcheck.net
– Cyrus
Apr 11 '15 at 16:25












Shellcheck says it is all looking good, but I still get the error.
– CYQ00000A
Apr 11 '15 at 16:50




Shellcheck says it is all looking good, but I still get the error.
– CYQ00000A
Apr 11 '15 at 16:50




2




2




Works for me. Have you really posted the code you're running? Seems like $counter is empty in your real code (use "$counter").
– choroba
Apr 11 '15 at 16:53




Works for me. Have you really posted the code you're running? Seems like $counter is empty in your real code (use "$counter").
– choroba
Apr 11 '15 at 16:53










1 Answer
1






active

oldest

votes

















up vote
0
down vote













Try this:



#!/bin/bash
clear
counter=0

function countup
while [[ $counter -lt 500 ]]; do
((counter++))
echo $counter
sleep 0.2
done

countdown


function countdown
while [[ $counter -gt 0 ]]; do
((counter--))
echo $counter
sleep 0.2
done

countup


countup


[[ ]] is a bit more robust to unvalued variables. But, this script does run. It seems that you typed it differently here than your machine. This also looks like it will count up and down forever, but that seems to be intentional.






share|improve this answer




















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    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: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f195651%2fcounting-program-fails-in-arithmetic-test%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
    0
    down vote













    Try this:



    #!/bin/bash
    clear
    counter=0

    function countup
    while [[ $counter -lt 500 ]]; do
    ((counter++))
    echo $counter
    sleep 0.2
    done

    countdown


    function countdown
    while [[ $counter -gt 0 ]]; do
    ((counter--))
    echo $counter
    sleep 0.2
    done

    countup


    countup


    [[ ]] is a bit more robust to unvalued variables. But, this script does run. It seems that you typed it differently here than your machine. This also looks like it will count up and down forever, but that seems to be intentional.






    share|improve this answer
























      up vote
      0
      down vote













      Try this:



      #!/bin/bash
      clear
      counter=0

      function countup
      while [[ $counter -lt 500 ]]; do
      ((counter++))
      echo $counter
      sleep 0.2
      done

      countdown


      function countdown
      while [[ $counter -gt 0 ]]; do
      ((counter--))
      echo $counter
      sleep 0.2
      done

      countup


      countup


      [[ ]] is a bit more robust to unvalued variables. But, this script does run. It seems that you typed it differently here than your machine. This also looks like it will count up and down forever, but that seems to be intentional.






      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        Try this:



        #!/bin/bash
        clear
        counter=0

        function countup
        while [[ $counter -lt 500 ]]; do
        ((counter++))
        echo $counter
        sleep 0.2
        done

        countdown


        function countdown
        while [[ $counter -gt 0 ]]; do
        ((counter--))
        echo $counter
        sleep 0.2
        done

        countup


        countup


        [[ ]] is a bit more robust to unvalued variables. But, this script does run. It seems that you typed it differently here than your machine. This also looks like it will count up and down forever, but that seems to be intentional.






        share|improve this answer












        Try this:



        #!/bin/bash
        clear
        counter=0

        function countup
        while [[ $counter -lt 500 ]]; do
        ((counter++))
        echo $counter
        sleep 0.2
        done

        countdown


        function countdown
        while [[ $counter -gt 0 ]]; do
        ((counter--))
        echo $counter
        sleep 0.2
        done

        countup


        countup


        [[ ]] is a bit more robust to unvalued variables. But, this script does run. It seems that you typed it differently here than your machine. This also looks like it will count up and down forever, but that seems to be intentional.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jun 25 '15 at 5:34









        Will

        1,451722




        1,451722



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f195651%2fcounting-program-fails-in-arithmetic-test%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay