[Makefile]添加颜色在OS X上不起作用 [英] [Makefile]Adding colors doesn't work on OS X
问题描述
我最近切换到Macbook Air,因此切换到OS X.
我导入了一些我当前的项目,并尝试用我的Makefile编译它们。
I recently switched to a Macbook Air and thus to OS X. I imported some of my current projects to it and tried to compile them with my Makefile.
我的Makefile有一些自定义输入,用/ bin / echo -e添加颜色\033 [0; 31m例如+文本。它在我的旧计算机上工作伟大(OpenSuse distrib),但它甚至不编译我的二进制文件在我的Mac上了。
这是当我尝试通过我的Makefile提示自定义行时,我得到的:
My Makefile has some custom imput adding colors with /bin/echo -e "\033[0;31m" for example + the text. It's working great on my old computer (OpenSuse distrib) but it doesn't even compile my binary anymore on my Mac. Here's what I get when I try to prompt a custom line through my Makefile :
-e \033[0;31m (MY TEXT) \033[00m
o文件,它们都不会被编译,所以我的项目构建失败。
我的Makefile工作伟大没有这些自定义输出,但我想知道为什么他们不工作在OS X。
As I use custom imput when compiling my .o files, none of them are get compiled so my project build fail. My Makefile work great without these custom output but I'd like to know why they don't work on OS X.
我可以发布我的Makefile代码如果有人要求进一步调查。
I can post my Makefile code if some people request it for further investigation.
推荐答案
这是类似的,但不是一个重复的颜色termcaps Konsole?。问题是 -e
不是 OSX echo (其中 POSIX )。如果你取出 -e
,它会按照你的期望工作。
This is similar, but not quite a duplicate of Color termcaps Konsole?. The problem is that -e
is not an option of OSX echo (which follows POSIX). If you take out the -e
, it will work as you expect.
-e
选项在某些实现中用于允许 \e
作为 \033
The -e
option is used in some implementations to allow \e
as a synonym for \033
(but your example uses the latter anyway).
无论您是使用 echo
还是 printf
用于POSIX脚本很大程度上是一个问题,因为它们都接受同一组反斜杠序列。例如 printf
当然接受用于格式化数字的%
序列,但是C ++程序员已经习惯了cout vs echo)不使用 printf
类型调用。
Whether you use echo
or printf
for POSIX scripts is largely a matter of taste, since both accept the same set of backslash sequences. For example printf
, of course, accepts %
sequences for formatting numbers, but C++ programmers have gotten into the habit of (cout vs echo) not using the printf
-style calls.
供参考。
- printf - write formatted output
- echo - write arguments to standard output
这篇关于[Makefile]添加颜色在OS X上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!