开发者

Continue output on same line

Want to do a fancy effect by printing [OK] at the end of the last line when a task is finished.

Got this:

echo "$0: 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.

I want it to output this:

./backup.sh: Starting backup process in '/backup'...

... And 3 sec later, add the [OK]:

./backup.sh: Starting backup process in '/backup'... [OK]

Thanks,


Use the -n option to skip printing newline at the end. More reference at echo docs.

So you could do something like this:

echo -n "$0: Starting backup process in '$backupdir'... " 


use the more portable printf:

printf "%s" "$0: Starting backup process in '$backupdir'... "
sleep 3
printf '[OK]\n'


echo -n hello

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜