ubuntu中的echo -e选项不起作用

How*_*hen 5 shell ubuntu makefile

我的同事使用Ubuntu并且我使用openSUSE,我们使用相同的makefile编译相同的源代码,我的环境运行良好,但我的同事不能,总是输出无法识别的-e选项.我们检查makefile,只查找echo命令使用-e选项.

剂量Ubuntu的回声功能与其他功能不同?

在makefile中+++++更新,echo定义为:

TOOLSDIR =

ECHO = $(TOOLSDIR)echo -e

$(TOOLSDIR)是工具的目录,这个make文件可以检测编译环境,如果linux或者有CYGWIN:

$(TOOLSDIR)是空的,如果是windows,它会转到WIN32版本的echo工具目录,如:

TOOLSDIR = $(subst /,\,$(MAKEDIR)/tools/WIN32/)

在我们执行make之后,ubuntu将输出:

致命错误:L3900U:无法识别的选项'-e'.

但是,openSUSE没有此错误

++++更新echo -e

我在ubuntu中编写了一个测试makefile

all:
    echo -e hello
Run Code Online (Sandbox Code Playgroud)

它输出:

echo -e你好

你好

++++更新makefile测试在openSUE(12.1)和ubuntu(12.04)

all:
    echo -e "hello 1"
    echo -e hello 2
    echo -e he\nllo3
    echo -e "he\nllo4"
Run Code Online (Sandbox Code Playgroud)
  1. opensuse,输出是:

echo -e"你好1"

你好1

echo -e你好2

你好2

echo -e he \nllo3

henllo3

echo -e"he \nllo4"

llo4

  1. 在ubuntu中,输出是:

echo -e"你好1"

你好1

echo -e你好2

你好2

echo -e he \nllo3

henllo3

echo -e"he \nllo4"

- 他

llo4

同时,我在ubuntu中测试,echo没有-e,结果与openSUSE相同,echo with-e

Lui*_*ano 6

它可能取决于你们正在使用的shell(echo经常在shell中实现)

这是OS X(Mountain Lion)中发生的事情:

$ bash
bash-4.2$ echo -e foo
foo
bash-4.2$ sh
sh-3.2$ echo -e foo
-e foo
Run Code Online (Sandbox Code Playgroud)

OpenSUSE和Ubuntu也一样.

-e选项不符合POSIX(我不确定,但它应该是默认行为),顺便说一句,打印格式化文本,printf是更合适的命令.

根据您提供的信息,我认为您的makefile存在错误(可移植性问题).

在OSX上man echo也没有列出该-e选项,顺便说一句.在Ubuntu 12.10 -e上,我的计算机上存在,我的路由器BusyBox v1.13.4也接受-e(它是busybox的内部命令)

但可能只是/bin/sh使用内部命令并忽略它.

====更新:

在你的makefile中删除echo前面的$(TOOLSDIR):

ECHO = echo -e
Run Code Online (Sandbox Code Playgroud)

实际上,如果指定echo的路径(即/bin/echo),则强制shell从文件系统执行程序,而不是shell内部实现的程序:

$ echo -e foo
foo
$ /bin/echo -e foo
-e foo
Run Code Online (Sandbox Code Playgroud)