'echo'在shell脚本中没有换行符 [英] 'echo' without newline in a shell script
本文介绍了'echo'在shell脚本中没有换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的脚本中有 echo
的问题:
echo -n "Some string..."
打印
-n Some string...
并移动到下一行。在控制台中它正常工作没有换行符:
and moves to the next line. In the console it's working correcly without newline:
Some string...
推荐答案
有多个版本的tbe echo
命令,具有不同的行为。显然,用于您脚本的shell使用的版本不能识别 -n
。
There are multiple versions of tbe echo
command, with different behaviors. Apparently the shell used for your script uses a version that doesn't recognize -n
.
$ c> printf 命令具有更加一致的行为。 echo
适用于 echo hello
等简单的事情,但我建议使用 printf $
The printf
command has much more consistent behavior. echo
is fine for simple things like echo hello
, but I suggest using printf
for anything more complicated.
你使用什么系统,脚本使用什么shell?
What system are you on, and what shell does your script use?
这篇关于'echo'在shell脚本中没有换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文