bash 重击打印“\r”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8794718/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 01:15:47  来源:igfitidea点击:

Bash printing "\r"

bashreturnecho

提问by user1137042

I'm using OS X, and there is no "-e" equivalent.

我使用的是 OS X,没有“-e”等价物。

How can I textually print "\r"? Is there even a way to do that?

如何以文本方式打印“\r”?有没有办法做到这一点?

回答by SiegeX

You could use echo $'\r'which is supported by bash

您可以使用echo $'\r'支持的bash

回答by Mithrandir

How about:

怎么样:

echo "\r"

Works for me.

对我来说有效。

回答by Keith Thompson

printf '\r'

The printfcommand in general tends to be better than echofor cases other than very simple ones. It has more capabilities and fewer variations from one implementation to another.

printf命令通常echo比非常简单的情况以外的情况更好。从一种实现到另一种实现,它具有更多的功能和更少的变化。

回答by ?mega

Script:

脚本:

#!/bin/bash
r=$'\r'
t=$'\t'
echo "${t}${t}1${r}${t}2${r}3"

Output:

输出:

3       2       1