“回声-n"打印“-n" [英] "echo -n" prints "-n"

查看:46
本文介绍了“回声-n"打印“-n"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的脚本中的 echo 有问题:

I have a problem with echo in my script:

echo -n "Some string..."

印刷品

-n Some string...

并移动到下一行.在控制台中,它在没有换行符的情况下正常工作:

and moves to the next line. In the console it's working correcly without newline:

Some string...

推荐答案

echo 命令有多个版本,具有不同的行为.显然,用于脚本的 shell 使用的版本无法识别 -n.

There are multiple versions of the echo command, with different behaviors. Apparently the shell used for your script uses a version that doesn't recognize -n.

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?

这篇关于“回声-n"打印“-n"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆