error `conditional binary operator expected` in compound branch

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











up vote
0
down vote

favorite












I am running such a program:



 min_val=1
max_val=100
int=50
if [[ "$int" =~ ^-?[0-9]+$ ]]; then
if [[ "$int" -ge "$min_val" && -le "$max_val" ]]; then
echo "$int is within $min_val to $max_val."
else
echo "$int is out of range."
fi
else
echo "int is not an integer." >&2
exit 1
fi


It report error



 $ bash test_integer3.sh
test_integer3.sh: line 12: conditional binary operator expectedtest_integer3.sh:
line 12: syntax error near `"$max_val"'test_integer3.sh:
line 12: ` if [[ "$int" -ge "$min_val" && -le "$max_val" ]]; then'


I have examined carefully line-by-line.



What might be the problem?







share|improve this question


















  • 1




    Add a shebang and then paste your script there: shellcheck.net
    – Cyrus
    Apr 3 at 5:35














up vote
0
down vote

favorite












I am running such a program:



 min_val=1
max_val=100
int=50
if [[ "$int" =~ ^-?[0-9]+$ ]]; then
if [[ "$int" -ge "$min_val" && -le "$max_val" ]]; then
echo "$int is within $min_val to $max_val."
else
echo "$int is out of range."
fi
else
echo "int is not an integer." >&2
exit 1
fi


It report error



 $ bash test_integer3.sh
test_integer3.sh: line 12: conditional binary operator expectedtest_integer3.sh:
line 12: syntax error near `"$max_val"'test_integer3.sh:
line 12: ` if [[ "$int" -ge "$min_val" && -le "$max_val" ]]; then'


I have examined carefully line-by-line.



What might be the problem?







share|improve this question


















  • 1




    Add a shebang and then paste your script there: shellcheck.net
    – Cyrus
    Apr 3 at 5:35












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am running such a program:



 min_val=1
max_val=100
int=50
if [[ "$int" =~ ^-?[0-9]+$ ]]; then
if [[ "$int" -ge "$min_val" && -le "$max_val" ]]; then
echo "$int is within $min_val to $max_val."
else
echo "$int is out of range."
fi
else
echo "int is not an integer." >&2
exit 1
fi


It report error



 $ bash test_integer3.sh
test_integer3.sh: line 12: conditional binary operator expectedtest_integer3.sh:
line 12: syntax error near `"$max_val"'test_integer3.sh:
line 12: ` if [[ "$int" -ge "$min_val" && -le "$max_val" ]]; then'


I have examined carefully line-by-line.



What might be the problem?







share|improve this question














I am running such a program:



 min_val=1
max_val=100
int=50
if [[ "$int" =~ ^-?[0-9]+$ ]]; then
if [[ "$int" -ge "$min_val" && -le "$max_val" ]]; then
echo "$int is within $min_val to $max_val."
else
echo "$int is out of range."
fi
else
echo "int is not an integer." >&2
exit 1
fi


It report error



 $ bash test_integer3.sh
test_integer3.sh: line 12: conditional binary operator expectedtest_integer3.sh:
line 12: syntax error near `"$max_val"'test_integer3.sh:
line 12: ` if [[ "$int" -ge "$min_val" && -le "$max_val" ]]; then'


I have examined carefully line-by-line.



What might be the problem?









share|improve this question













share|improve this question




share|improve this question








edited Apr 3 at 5:43

























asked Apr 3 at 5:29









JawSaw

29410




29410







  • 1




    Add a shebang and then paste your script there: shellcheck.net
    – Cyrus
    Apr 3 at 5:35












  • 1




    Add a shebang and then paste your script there: shellcheck.net
    – Cyrus
    Apr 3 at 5:35







1




1




Add a shebang and then paste your script there: shellcheck.net
– Cyrus
Apr 3 at 5:35




Add a shebang and then paste your script there: shellcheck.net
– Cyrus
Apr 3 at 5:35










2 Answers
2






active

oldest

votes

















up vote
2
down vote



accepted










if [[ "$int" -ge "$min_val" && -le "$max_val" ]]; then


You will have to compare against $int in both comparisons:



if [[ "$int" -ge "$min_val" ]] && [[ "$int" -le "$max_val" ]]; then


or,



if (( int >= min_val )) && (( int <= max_val )); then





share|improve this answer



























    up vote
    4
    down vote













    Your -le doesn't have a left operand.






    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%2f435193%2ferror-conditional-binary-operator-expected-in-compound-branch%23new-answer', 'question_page');

      );

      Post as a guest






























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      2
      down vote



      accepted










      if [[ "$int" -ge "$min_val" && -le "$max_val" ]]; then


      You will have to compare against $int in both comparisons:



      if [[ "$int" -ge "$min_val" ]] && [[ "$int" -le "$max_val" ]]; then


      or,



      if (( int >= min_val )) && (( int <= max_val )); then





      share|improve this answer
























        up vote
        2
        down vote



        accepted










        if [[ "$int" -ge "$min_val" && -le "$max_val" ]]; then


        You will have to compare against $int in both comparisons:



        if [[ "$int" -ge "$min_val" ]] && [[ "$int" -le "$max_val" ]]; then


        or,



        if (( int >= min_val )) && (( int <= max_val )); then





        share|improve this answer






















          up vote
          2
          down vote



          accepted







          up vote
          2
          down vote



          accepted






          if [[ "$int" -ge "$min_val" && -le "$max_val" ]]; then


          You will have to compare against $int in both comparisons:



          if [[ "$int" -ge "$min_val" ]] && [[ "$int" -le "$max_val" ]]; then


          or,



          if (( int >= min_val )) && (( int <= max_val )); then





          share|improve this answer












          if [[ "$int" -ge "$min_val" && -le "$max_val" ]]; then


          You will have to compare against $int in both comparisons:



          if [[ "$int" -ge "$min_val" ]] && [[ "$int" -le "$max_val" ]]; then


          or,



          if (( int >= min_val )) && (( int <= max_val )); then






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Apr 3 at 5:44









          Kusalananda

          102k13201317




          102k13201317






















              up vote
              4
              down vote













              Your -le doesn't have a left operand.






              share|improve this answer
























                up vote
                4
                down vote













                Your -le doesn't have a left operand.






                share|improve this answer






















                  up vote
                  4
                  down vote










                  up vote
                  4
                  down vote









                  Your -le doesn't have a left operand.






                  share|improve this answer












                  Your -le doesn't have a left operand.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Apr 3 at 5:39









                  user1934428

                  35119




                  35119






















                       

                      draft saved


                      draft discarded


























                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f435193%2ferror-conditional-binary-operator-expected-in-compound-branch%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Popular posts from this blog

                      Peggy Mitchell

                      Palaiologos

                      The Forum (Inglewood, California)