简体   繁体   English

bash:多个echo命令的结果,在一行上有延迟?

[英]bash: result of multiple echo commands with a delay on one line?

I'm learning the basics on bash scripting, and basically what I'm trying to do is have an output of "..." with a pause in between each period. 我正在学习关于bash脚本的基础知识,基本上我要做的是输出“...”并在每个句点之间暂停。

I've tried echo . ; sleep 1 ;echo . ; sleep 1 ; echo . ; sleep 1 我试过echo . ; sleep 1 ;echo . ; sleep 1 ; echo . ; sleep 1 echo . ; sleep 1 ;echo . ; sleep 1 ; echo . ; sleep 1 echo . ; sleep 1 ;echo . ; sleep 1 ; echo . ; sleep 1 and other ways but the output is always vertically, line by line. echo . ; sleep 1 ;echo . ; sleep 1 ; echo . ; sleep 1和其他方式,但输出始终是垂直,逐行。 I'm aware of what ";" 我知道什么是“;” and "&&" does but I'm just learning, and the only way that seemed close was a "echo . `sleep 1 command... Is echo or sleep even the right command for this? 而“&&”确实如此,但我只是在学习,而且看起来很接近的唯一方法就是“回声。”睡眠1命令......回声或睡眠甚至是正确的命令吗?

Sorry for being so dim-witted but I just can't figure this out! 对不起,我是如此笨拙,但我无法弄清楚这一点!

if your are looking to echo ... 如果你想要回应...

echo "..." ; sleep 1 ;echo "..." ; sleep 1 ; echo "..." ; sleep 1

echo as the name implies is to "output" and yes "sleep" is definitely the command you need to for pausing. 名称暗示的回声是“输出”,是“睡眠”绝对是暂停所需的命令。

if you want to use echo and output ... on the same line three times. 如果你想在同一行使用echo和output ...三次。 you can use 您可以使用

 echo -n "..." ; sleep 1 ;echo -n "..." ; sleep 1 ; echo -n "..." ; sleep 1

echo automatically prints a newline after its arguments. echo在其参数后自动打印换行符。 To suppress it, you might be able to use the -n option, but that isn't universally supported. 要禁止它,您可以使用-n选项,但这不是普遍支持的。 Instead, use printf . 相反,使用printf

printf '.'; sleep 1; printf '.'; sleep 1; printf '.'; sleep 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM