I was actually able to figure this out, and I figure I'd add it here for the next googler who bangs their head against the same wall.
I had a grep alias and GREP_OPTIONS
set. This caused color highlighting to remain on in the script, even when piping to another command. That usually doesn't play nicely with sed
.
Here's my .alias and options:
alias grep='grep -i --color'
export GREP_OPTIONS="--color=always"
So when running from the script, it doesn't use the aliased command and so forces color to always be on. So when I checked my alias and saw the --color
option (which means auto
, which means "don't color output that gets piped to another command" (like sed
).
I was confused because I forgot I had set GREP_OPTIONS
as well, so I expected the grep
in the script to have color
set to auto
by default (as it would if I hadn't set the global GREP_OPTIONS
). But not so.
Here are my new settings (I believe the --color
flag to GREP_OPTIONS
is redundant, but I leave it there as a reminder):
alias grep='grep --color=always'
export GREP_OPTIONS="--ignore-case --color"
That way, any time I am on the command line, I'll have highlighting on for all my greps (which is usually what I want). But in scripts it will default to coloring only when not piped to another command. I'll still have to add --color=always to many of my scripts (since I tend to prefer highlighting in most cases, even when piping to another command, unless I don't ever see the output).
$urls
already have a value when in shell mode? – LatinSuD Jul 10 '14 at 15:07GREP_OPTIONS
are forcingcolor
toalways
, while my command-linegrep
is using an alias that is automatically turning off coloring due to the piped grep output. Sosed
is getting color codes sent to it. Will give more details tonight when it let's me add an answer. – kghastie Jul 10 '14 at 15:13--color=always
? That's a very bad idea. – terdon♦ Jul 10 '14 at 15:25--color-auto
is for. It is intelligent enough to add it when you want it but not when you don't. – terdon♦ Jul 10 '14 at 16:05