Why did I get `[three: command not found` from my Bash script? What to do about it? [duplicate]

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












-3
















This question already has an answer here:



  • Brackets in if condition: why am I getting syntax errors without whitespace?

    3 answers



I was testing a Bash script that accepts random arguments and noticed that it would say something like



./Var: line 19: [three: command not found


Here is a minimal working example:



#!/bin/bash
$1 $2 $3

echo "The first argument does $1"
if [$1 >= 2]; then
echo "$1 has 2 words"
else
echo "$1 has unknown amount of words"
fi
#^First
echo "The second argument does $2"
if [$2 >= 2]; then
echo "$2 has 2 words"
else
echo "$2 has unknown amount of words"
fi
#^Second
echo "The third argument does $3"
if [$3 >= 2]; then
echo "$3 has 2 words"
fi
#^Third


But it would continue to run the script, is there a way i can have it run without the "command not found" appearing? Or is this just an issue within my code that is making it do this?










share|improve this question















marked as duplicate by Jeff Schaller, roaima, ilkkachu bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Jan 21 at 21:57


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






















    -3
















    This question already has an answer here:



    • Brackets in if condition: why am I getting syntax errors without whitespace?

      3 answers



    I was testing a Bash script that accepts random arguments and noticed that it would say something like



    ./Var: line 19: [three: command not found


    Here is a minimal working example:



    #!/bin/bash
    $1 $2 $3

    echo "The first argument does $1"
    if [$1 >= 2]; then
    echo "$1 has 2 words"
    else
    echo "$1 has unknown amount of words"
    fi
    #^First
    echo "The second argument does $2"
    if [$2 >= 2]; then
    echo "$2 has 2 words"
    else
    echo "$2 has unknown amount of words"
    fi
    #^Second
    echo "The third argument does $3"
    if [$3 >= 2]; then
    echo "$3 has 2 words"
    fi
    #^Third


    But it would continue to run the script, is there a way i can have it run without the "command not found" appearing? Or is this just an issue within my code that is making it do this?










    share|improve this question















    marked as duplicate by Jeff Schaller, roaima, ilkkachu bash
    Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

    StackExchange.ready(function()
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function()
    $hover.showInfoMessage('',
    messageElement: $msg.clone().show(),
    transient: false,
    position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
    dismissable: false,
    relativeToBody: true
    );
    ,
    function()
    StackExchange.helpers.removeMessages();

    );
    );
    );
    Jan 21 at 21:57


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.




















      -3












      -3








      -3









      This question already has an answer here:



      • Brackets in if condition: why am I getting syntax errors without whitespace?

        3 answers



      I was testing a Bash script that accepts random arguments and noticed that it would say something like



      ./Var: line 19: [three: command not found


      Here is a minimal working example:



      #!/bin/bash
      $1 $2 $3

      echo "The first argument does $1"
      if [$1 >= 2]; then
      echo "$1 has 2 words"
      else
      echo "$1 has unknown amount of words"
      fi
      #^First
      echo "The second argument does $2"
      if [$2 >= 2]; then
      echo "$2 has 2 words"
      else
      echo "$2 has unknown amount of words"
      fi
      #^Second
      echo "The third argument does $3"
      if [$3 >= 2]; then
      echo "$3 has 2 words"
      fi
      #^Third


      But it would continue to run the script, is there a way i can have it run without the "command not found" appearing? Or is this just an issue within my code that is making it do this?










      share|improve this question

















      This question already has an answer here:



      • Brackets in if condition: why am I getting syntax errors without whitespace?

        3 answers



      I was testing a Bash script that accepts random arguments and noticed that it would say something like



      ./Var: line 19: [three: command not found


      Here is a minimal working example:



      #!/bin/bash
      $1 $2 $3

      echo "The first argument does $1"
      if [$1 >= 2]; then
      echo "$1 has 2 words"
      else
      echo "$1 has unknown amount of words"
      fi
      #^First
      echo "The second argument does $2"
      if [$2 >= 2]; then
      echo "$2 has 2 words"
      else
      echo "$2 has unknown amount of words"
      fi
      #^Second
      echo "The third argument does $3"
      if [$3 >= 2]; then
      echo "$3 has 2 words"
      fi
      #^Third


      But it would continue to run the script, is there a way i can have it run without the "command not found" appearing? Or is this just an issue within my code that is making it do this?





      This question already has an answer here:



      • Brackets in if condition: why am I getting syntax errors without whitespace?

        3 answers







      bash shell-script






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 21 at 20:40









      Kamil Maciorowski

      1,6081828




      1,6081828










      asked Jan 21 at 19:21









      RepoSepoRepoSepo

      13




      13




      marked as duplicate by Jeff Schaller, roaima, ilkkachu bash
      Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

      StackExchange.ready(function()
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function()
      $hover.showInfoMessage('',
      messageElement: $msg.clone().show(),
      transient: false,
      position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
      dismissable: false,
      relativeToBody: true
      );
      ,
      function()
      StackExchange.helpers.removeMessages();

      );
      );
      );
      Jan 21 at 21:57


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









      marked as duplicate by Jeff Schaller, roaima, ilkkachu bash
      Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

      StackExchange.ready(function()
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function()
      $hover.showInfoMessage('',
      messageElement: $msg.clone().show(),
      transient: false,
      position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
      dismissable: false,
      relativeToBody: true
      );
      ,
      function()
      StackExchange.helpers.removeMessages();

      );
      );
      );
      Jan 21 at 21:57


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






















          1 Answer
          1






          active

          oldest

          votes


















          1














          The command you want to use is [ (or test), not [whatever, so it should be (for example)



          [ "$3" -ge 2 ]


          instead of [$3 >= 2], which generates [three: command not found if $3 is three. Additionally:



          • quote your variables;


          • [ doesn't understand >=, it understands -ge and other options;


          • >= is a redirection anyway and it didn't get to the command, regardless if the command was [ or [three. You now have a file named =.

          In Bash [ is a builtin. See help [, help test.






          share|improve this answer





























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            The command you want to use is [ (or test), not [whatever, so it should be (for example)



            [ "$3" -ge 2 ]


            instead of [$3 >= 2], which generates [three: command not found if $3 is three. Additionally:



            • quote your variables;


            • [ doesn't understand >=, it understands -ge and other options;


            • >= is a redirection anyway and it didn't get to the command, regardless if the command was [ or [three. You now have a file named =.

            In Bash [ is a builtin. See help [, help test.






            share|improve this answer



























              1














              The command you want to use is [ (or test), not [whatever, so it should be (for example)



              [ "$3" -ge 2 ]


              instead of [$3 >= 2], which generates [three: command not found if $3 is three. Additionally:



              • quote your variables;


              • [ doesn't understand >=, it understands -ge and other options;


              • >= is a redirection anyway and it didn't get to the command, regardless if the command was [ or [three. You now have a file named =.

              In Bash [ is a builtin. See help [, help test.






              share|improve this answer

























                1












                1








                1







                The command you want to use is [ (or test), not [whatever, so it should be (for example)



                [ "$3" -ge 2 ]


                instead of [$3 >= 2], which generates [three: command not found if $3 is three. Additionally:



                • quote your variables;


                • [ doesn't understand >=, it understands -ge and other options;


                • >= is a redirection anyway and it didn't get to the command, regardless if the command was [ or [three. You now have a file named =.

                In Bash [ is a builtin. See help [, help test.






                share|improve this answer













                The command you want to use is [ (or test), not [whatever, so it should be (for example)



                [ "$3" -ge 2 ]


                instead of [$3 >= 2], which generates [three: command not found if $3 is three. Additionally:



                • quote your variables;


                • [ doesn't understand >=, it understands -ge and other options;


                • >= is a redirection anyway and it didn't get to the command, regardless if the command was [ or [three. You now have a file named =.

                In Bash [ is a builtin. See help [, help test.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 21 at 19:51









                Kamil MaciorowskiKamil Maciorowski

                1,6081828




                1,6081828












                    Popular posts from this blog

                    Peggy Mitchell

                    Palaiologos

                    The Forum (Inglewood, California)