Does grep --color default to =auto or =always?
Clash 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 foo
bar
, while
echo "foo bar" | grep --color foo | grep --color bar
results in foo
bar
, 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
add a comment |Â
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 foo
bar
, while
echo "foo bar" | grep --color foo | grep --color bar
results in foo
bar
, 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
add a comment |Â
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 foo
bar
, while
echo "foo bar" | grep --color foo | grep --color bar
results in foo
bar
, 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
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 foo
bar
, while
echo "foo bar" | grep --color foo | grep --color bar
results in foo
bar
, 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
grep colors
edited 6 mins ago
Fabby
2,68411023
2,68411023
asked 52 mins ago
OnlineCop
1163
1163
add a comment |Â
add a comment |Â
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
.
add a comment |Â
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
.
add a comment |Â
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
.
add a comment |Â
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
.
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
.
edited 31 mins ago
Stephen Kitt
154k23340409
154k23340409
answered 40 mins ago
mosvy
3,600119
3,600119
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password