Does grep --color default to =auto or =always?

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











up vote
2
down vote

favorite












What is the default color behavior for grep --color if no [=WHEN] is specified?



The grep man page states:


--color[=WHEN], --colour[=WHEN]
Surround the matched (non-empty) strings, matching lines, context lines,
file names, line numbers, byte offsets, and separators (for fields and
groups of context lines) with escape sequences to display them in color
on the terminal.
...
WHEN is never, always, or auto.



Does the default [=WHEN] for grep --color become:



grep --color=auto


or



grep --color=always


or does it depend on implementation and platform?



In my tests on Ubuntu 14.04 with GNU grep 2.16:



echo "foo bar" | grep --color foo


results in foobar, while



echo "foo bar" | grep --color foo | grep --color bar


results in foobar, so it appears that grep --color=auto is in effect here. I have not tested this on Windows or Mac, however; I don't know if this behavior is universal.



This default for [=WHEN] is a little different from ls --color where the man page for ls states:

--color[=WHEN]
colorize the output. WHEN defaults to always or can be never or auto.



Here, the behavior of the missing WHEN is explicit.










share|improve this question



























    up vote
    2
    down vote

    favorite












    What is the default color behavior for grep --color if no [=WHEN] is specified?



    The grep man page states:


    --color[=WHEN], --colour[=WHEN]
    Surround the matched (non-empty) strings, matching lines, context lines,
    file names, line numbers, byte offsets, and separators (for fields and
    groups of context lines) with escape sequences to display them in color
    on the terminal.
    ...
    WHEN is never, always, or auto.



    Does the default [=WHEN] for grep --color become:



    grep --color=auto


    or



    grep --color=always


    or does it depend on implementation and platform?



    In my tests on Ubuntu 14.04 with GNU grep 2.16:



    echo "foo bar" | grep --color foo


    results in foobar, while



    echo "foo bar" | grep --color foo | grep --color bar


    results in foobar, so it appears that grep --color=auto is in effect here. I have not tested this on Windows or Mac, however; I don't know if this behavior is universal.



    This default for [=WHEN] is a little different from ls --color where the man page for ls states:

    --color[=WHEN]
    colorize the output. WHEN defaults to always or can be never or auto.



    Here, the behavior of the missing WHEN is explicit.










    share|improve this question

























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      What is the default color behavior for grep --color if no [=WHEN] is specified?



      The grep man page states:


      --color[=WHEN], --colour[=WHEN]
      Surround the matched (non-empty) strings, matching lines, context lines,
      file names, line numbers, byte offsets, and separators (for fields and
      groups of context lines) with escape sequences to display them in color
      on the terminal.
      ...
      WHEN is never, always, or auto.



      Does the default [=WHEN] for grep --color become:



      grep --color=auto


      or



      grep --color=always


      or does it depend on implementation and platform?



      In my tests on Ubuntu 14.04 with GNU grep 2.16:



      echo "foo bar" | grep --color foo


      results in foobar, while



      echo "foo bar" | grep --color foo | grep --color bar


      results in foobar, so it appears that grep --color=auto is in effect here. I have not tested this on Windows or Mac, however; I don't know if this behavior is universal.



      This default for [=WHEN] is a little different from ls --color where the man page for ls states:

      --color[=WHEN]
      colorize the output. WHEN defaults to always or can be never or auto.



      Here, the behavior of the missing WHEN is explicit.










      share|improve this question















      What is the default color behavior for grep --color if no [=WHEN] is specified?



      The grep man page states:


      --color[=WHEN], --colour[=WHEN]
      Surround the matched (non-empty) strings, matching lines, context lines,
      file names, line numbers, byte offsets, and separators (for fields and
      groups of context lines) with escape sequences to display them in color
      on the terminal.
      ...
      WHEN is never, always, or auto.



      Does the default [=WHEN] for grep --color become:



      grep --color=auto


      or



      grep --color=always


      or does it depend on implementation and platform?



      In my tests on Ubuntu 14.04 with GNU grep 2.16:



      echo "foo bar" | grep --color foo


      results in foobar, while



      echo "foo bar" | grep --color foo | grep --color bar


      results in foobar, so it appears that grep --color=auto is in effect here. I have not tested this on Windows or Mac, however; I don't know if this behavior is universal.



      This default for [=WHEN] is a little different from ls --color where the man page for ls states:

      --color[=WHEN]
      colorize the output. WHEN defaults to always or can be never or auto.



      Here, the behavior of the missing WHEN is explicit.







      grep colors






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 6 mins ago









      Fabby

      2,68411023




      2,68411023










      asked 52 mins ago









      OnlineCop

      1163




      1163




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          5
          down vote













          It defaults to auto.



          grep --color is the same as writing --color=auto.



          This seems to be deficiently documented, or they consider the simple --color deprecated, but that can be seen both from testing and from its source code:



           case COLOR_OPTION:
          if (optarg)
          !strcasecmp (optarg, "tty")

          else
          color_option = 2;
          break;


          Notice that the lack of an optarg results in the same as it being equal to auto or tty.






          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: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            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%2f480172%2fdoes-grep-color-default-to-auto-or-always%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
            5
            down vote













            It defaults to auto.



            grep --color is the same as writing --color=auto.



            This seems to be deficiently documented, or they consider the simple --color deprecated, but that can be seen both from testing and from its source code:



             case COLOR_OPTION:
            if (optarg)
            !strcasecmp (optarg, "tty")

            else
            color_option = 2;
            break;


            Notice that the lack of an optarg results in the same as it being equal to auto or tty.






            share|improve this answer


























              up vote
              5
              down vote













              It defaults to auto.



              grep --color is the same as writing --color=auto.



              This seems to be deficiently documented, or they consider the simple --color deprecated, but that can be seen both from testing and from its source code:



               case COLOR_OPTION:
              if (optarg)
              !strcasecmp (optarg, "tty")

              else
              color_option = 2;
              break;


              Notice that the lack of an optarg results in the same as it being equal to auto or tty.






              share|improve this answer
























                up vote
                5
                down vote










                up vote
                5
                down vote









                It defaults to auto.



                grep --color is the same as writing --color=auto.



                This seems to be deficiently documented, or they consider the simple --color deprecated, but that can be seen both from testing and from its source code:



                 case COLOR_OPTION:
                if (optarg)
                !strcasecmp (optarg, "tty")

                else
                color_option = 2;
                break;


                Notice that the lack of an optarg results in the same as it being equal to auto or tty.






                share|improve this answer














                It defaults to auto.



                grep --color is the same as writing --color=auto.



                This seems to be deficiently documented, or they consider the simple --color deprecated, but that can be seen both from testing and from its source code:



                 case COLOR_OPTION:
                if (optarg)
                !strcasecmp (optarg, "tty")

                else
                color_option = 2;
                break;


                Notice that the lack of an optarg results in the same as it being equal to auto or tty.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 31 mins ago









                Stephen Kitt

                154k23340409




                154k23340409










                answered 40 mins ago









                mosvy

                3,600119




                3,600119



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f480172%2fdoes-grep-color-default-to-auto-or-always%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    What does second last employer means? [closed]

                    Installing NextGIS Connect into QGIS 3?

                    One-line joke