使用相同的命令 echo -ne "hello\n"
在bash和dash中会有不同的行为。具体如下:
$ bash -c 'echo -ne "hello\n"'
hello
$ dash -c 'echo -ne "hello\n"'
-ne hello
为什么会这样?我完全不理解...
我的系统:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 12.04.5 LTS
Release: 12.04
Codename: precise
echo
应该如何行事;Bash 忽略了该标准(这是极少数情况之一,不是扩展未定义的行为,而是完全不兼容)。 - Charles Duffyexport POSIXLY_CORRECT=1
,然后使用GNU的/bin/echo
,你会看到它的行为方式是相同的。 - Charles Duffybash
没有忽略,它只是默认没有选择那种行为。 - cuonglm