\n
不被识别为“变更线”。它只是打印\n
。
我的终端是gnome终端3.6.2。
首先,我通过echo命令注意到了它,然后通过shell脚本注意到了它。
关于它为什么不起作用的任何建议?
默认情况下,echo
Ubuntu随附的标准GNU版本不识别转义序列。使用该-e
标志来启用它。
比较输出:
serg@ubuntu(bash):[/home/xieerqi]$ echo "new\nline"
new\nline
serg@ubuntu(bash):[/home/xieerqi]$ echo -e "new\nline"
new
line
通常echo
,不建议在脚本中使用。例如,mksh
的echo
确实允许解释转义。
为了使脚本具有可移植性,请使用printf
函数。
serg@ubuntu(bash):[/home/xieerqi]$ printf "new\nline\n"
new
line
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句