shell 字符串换行输出问题

dash 中bash

echo 'hello\nworld'

将会输出ui

hello
world

bash 中code

echo 'hello\nworld'

将会输出nw

hello\nworld

通常状况下 /bin/sh 被软链到 /bin/dash,偶尔也会遇到有人把 /bin/sh 软链到 /bin/bash。就会出现结果与预期不符的状况。co

echo 在 dash 与 bash 中都是内建(builtin)的,使用外部命令 /bin/echo 能够避免差别。

/bin/echo -e 'hello\nworld'

输出

hello
world
相关文章
相关标签/搜索