bash 在同一行继续输出
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3372673/
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
Continue output on same line
提问by Johan
Want to do a fancy effect by printing [OK] at the end of the last line when a task is finished.
想通过在任务完成时在最后一行的末尾打印[OK]来做一个花哨的效果。
Got this:
明白啦:
echo "echo -n "printf "%s" "##代码##: Starting backup process in '$backupdir'... "
sleep 3
printf '[OK]\n'
: Starting backup process in '$backupdir'... "
: Starting backup process in '$backupdir'... "
sleep 3
echo '[OK]'
I tried different things at the end of the first echo, at the beginning of the second like \r
, \c
, \
, Googled it... No good.
我在第一个回声结束时尝试了不同的事情,在第二个回声开始时尝试了不同的东西,例如\r
, \c
, \
, 谷歌搜索...不好。
I want it to output this:
我希望它输出这个:
./backup.sh: Starting backup process in '/backup'...
./backup.sh: Starting backup process in '/backup'...
... And 3 sec later, add the [OK]
:
... 3 秒后,添加[OK]
:
./backup.sh: Starting backup process in '/backup'... [OK]
./backup.sh: Starting backup process in '/backup'... [OK]
Thanks,
谢谢,
回答by Johan
回答by ghostdog74
use the more portable printf
:
使用更便携printf
:
回答by ULysses
echo -n hello
echo -n hello