`nawk` "doesn't work" with `make`? Why?

1

I have the following alias:

alias mca_color='nawk '"'"'BEGIN { arr["Creating shared object"] = "1;31";} \
{ l = $0; for (pattern in arr) \
{ gsub(".*" pattern ".*", "\033[" arr[pattern] "m&\033[0m", l); } print l; }'"'"

I use similar aliases for coloring other outputs (using more patterns, but this is just for example).

So, this alias works, if I use it like:

$ echo "-ne Creating shared object test.so ..." | mca_color

the echo is printed in red. BUT, when I try:

$ make | mca_color

and even

$ make 2>&1 | mca_color

the result is not colored (and yes, make does "print" the same text at the end if its execution).

Any ideas?


I thought there could be something with child processes or something, but obviously the pipe works - tried it with grep, tried to redirect the output into a file, everything works.

Even this doesn't work (the text is printed, but not colored):

$ make 2>&1 | grep 'a' | mca_color

Kiril Kirov

Posted 2013-11-28T15:38:13.423

Reputation: 121

Have you compared the two outputs at byte level? – Marcus Rickert – 2013-11-28T21:44:32.033

All your suggested versions work for me, that is the text is printed in red. – Marcus Rickert – 2013-11-28T23:27:51.623

@MarcusRickert - At byte level - no, how can I do this? And even the make works? Interesting, I have no idea why it doesn't work here..... – Kiril Kirov – 2013-11-29T07:43:28.243

By byte level I mean that you try to look at the contents in hex mode. Some editors support this. This way you can find unvisible characters that might corrupt the pattern search. As a first test you can also compare the file lengths of the files that you pipe the output into and see if there is any difference in length. – Marcus Rickert – 2013-11-30T00:22:11.737

@MarcusRickert - I figured it out. You can see my answer. Stupid situation.. – Kiril Kirov – 2014-01-14T12:58:53.033

Answers

0

I finally figured it out, almost accidentally.

It appeared, that there was another alias make='colormake' and colormake is a script, containing:

/usr/bin/make "$@" 2>&1 | /usr/share/colormake/colormake.pl/usr/bin/make "$@" 2>&1 | /usr/share/colormake/colormake.pl

which explains a lot. Removing the alias for colormake fixed the "issue".

Kiril Kirov

Posted 2013-11-28T15:38:13.423

Reputation: 121

No idea why colormake didn't produce any colors, but I don't really care. – Kiril Kirov – 2014-01-14T14:16:23.490