builtin [ , -bash: [: missing `]'

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











up vote
2
down vote

favorite












while going through learn bash the hard way, I found that [ and test are both commands and synonyms, and both are builtin.

As it is a builtin it should not give any error for builtin [ , but I am getting -bash: [: missing `]',
Can someone explain me the behavior of builtin here.
Thanks in advance.



anupam:Markdown$ which [
/usr/bin/[
anupam:Markdown$ echo $?
0
anupam:Markdown$ which test
/usr/bin/test
anupam:Markdown$ echo $?
0
anupam:Markdown$ builtin test
anupam:Markdown$ echo $?
1
anupam:Markdown$ builtin [
-bash: [: missing `]'
anupam:Markdown$ echo $?
2
anupam:Markdown$









share|improve this question



























    up vote
    2
    down vote

    favorite












    while going through learn bash the hard way, I found that [ and test are both commands and synonyms, and both are builtin.

    As it is a builtin it should not give any error for builtin [ , but I am getting -bash: [: missing `]',
    Can someone explain me the behavior of builtin here.
    Thanks in advance.



    anupam:Markdown$ which [
    /usr/bin/[
    anupam:Markdown$ echo $?
    0
    anupam:Markdown$ which test
    /usr/bin/test
    anupam:Markdown$ echo $?
    0
    anupam:Markdown$ builtin test
    anupam:Markdown$ echo $?
    1
    anupam:Markdown$ builtin [
    -bash: [: missing `]'
    anupam:Markdown$ echo $?
    2
    anupam:Markdown$









    share|improve this question

























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      while going through learn bash the hard way, I found that [ and test are both commands and synonyms, and both are builtin.

      As it is a builtin it should not give any error for builtin [ , but I am getting -bash: [: missing `]',
      Can someone explain me the behavior of builtin here.
      Thanks in advance.



      anupam:Markdown$ which [
      /usr/bin/[
      anupam:Markdown$ echo $?
      0
      anupam:Markdown$ which test
      /usr/bin/test
      anupam:Markdown$ echo $?
      0
      anupam:Markdown$ builtin test
      anupam:Markdown$ echo $?
      1
      anupam:Markdown$ builtin [
      -bash: [: missing `]'
      anupam:Markdown$ echo $?
      2
      anupam:Markdown$









      share|improve this question















      while going through learn bash the hard way, I found that [ and test are both commands and synonyms, and both are builtin.

      As it is a builtin it should not give any error for builtin [ , but I am getting -bash: [: missing `]',
      Can someone explain me the behavior of builtin here.
      Thanks in advance.



      anupam:Markdown$ which [
      /usr/bin/[
      anupam:Markdown$ echo $?
      0
      anupam:Markdown$ which test
      /usr/bin/test
      anupam:Markdown$ echo $?
      0
      anupam:Markdown$ builtin test
      anupam:Markdown$ echo $?
      1
      anupam:Markdown$ builtin [
      -bash: [: missing `]'
      anupam:Markdown$ echo $?
      2
      anupam:Markdown$






      command-line bash






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 15 mins ago









      Melebius

      3,95051736




      3,95051736










      asked 29 mins ago









      jazzz

      59631336




      59631336




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote













          The [ version of the command requires ] as the mandatory last parameter (so it must be preceded by a space). It’s just a formal, syntactic thing to force users to close the bracketed “block”, so commands look this way:



          if [ $1 -eq 2 ]; then


          instead of



          if [ $1 -eq 2; then


          The test version does not require the final ] but accepts it. See help [:



          $ help [
          [: [ arg... ]
          Evaluate conditional expression.

          This is a synonym for the "test" builtin, but the last argument must
          be a literal `]', to match the opening `['.





          share|improve this answer






















          • Thanks @Melebius , so I checked for ` builtin [ ] ` and it worked .
            – jazzz
            15 mins ago










          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
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1083854%2fbuiltin-bash-missing%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













          The [ version of the command requires ] as the mandatory last parameter (so it must be preceded by a space). It’s just a formal, syntactic thing to force users to close the bracketed “block”, so commands look this way:



          if [ $1 -eq 2 ]; then


          instead of



          if [ $1 -eq 2; then


          The test version does not require the final ] but accepts it. See help [:



          $ help [
          [: [ arg... ]
          Evaluate conditional expression.

          This is a synonym for the "test" builtin, but the last argument must
          be a literal `]', to match the opening `['.





          share|improve this answer






















          • Thanks @Melebius , so I checked for ` builtin [ ] ` and it worked .
            – jazzz
            15 mins ago














          up vote
          3
          down vote













          The [ version of the command requires ] as the mandatory last parameter (so it must be preceded by a space). It’s just a formal, syntactic thing to force users to close the bracketed “block”, so commands look this way:



          if [ $1 -eq 2 ]; then


          instead of



          if [ $1 -eq 2; then


          The test version does not require the final ] but accepts it. See help [:



          $ help [
          [: [ arg... ]
          Evaluate conditional expression.

          This is a synonym for the "test" builtin, but the last argument must
          be a literal `]', to match the opening `['.





          share|improve this answer






















          • Thanks @Melebius , so I checked for ` builtin [ ] ` and it worked .
            – jazzz
            15 mins ago












          up vote
          3
          down vote










          up vote
          3
          down vote









          The [ version of the command requires ] as the mandatory last parameter (so it must be preceded by a space). It’s just a formal, syntactic thing to force users to close the bracketed “block”, so commands look this way:



          if [ $1 -eq 2 ]; then


          instead of



          if [ $1 -eq 2; then


          The test version does not require the final ] but accepts it. See help [:



          $ help [
          [: [ arg... ]
          Evaluate conditional expression.

          This is a synonym for the "test" builtin, but the last argument must
          be a literal `]', to match the opening `['.





          share|improve this answer














          The [ version of the command requires ] as the mandatory last parameter (so it must be preceded by a space). It’s just a formal, syntactic thing to force users to close the bracketed “block”, so commands look this way:



          if [ $1 -eq 2 ]; then


          instead of



          if [ $1 -eq 2; then


          The test version does not require the final ] but accepts it. See help [:



          $ help [
          [: [ arg... ]
          Evaluate conditional expression.

          This is a synonym for the "test" builtin, but the last argument must
          be a literal `]', to match the opening `['.






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 17 mins ago









          muru

          131k19278474




          131k19278474










          answered 22 mins ago









          Melebius

          3,95051736




          3,95051736











          • Thanks @Melebius , so I checked for ` builtin [ ] ` and it worked .
            – jazzz
            15 mins ago
















          • Thanks @Melebius , so I checked for ` builtin [ ] ` and it worked .
            – jazzz
            15 mins ago















          Thanks @Melebius , so I checked for ` builtin [ ] ` and it worked .
          – jazzz
          15 mins ago




          Thanks @Melebius , so I checked for ` builtin [ ] ` and it worked .
          – jazzz
          15 mins ago

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1083854%2fbuiltin-bash-missing%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

          One-line joke