开发者

Continue output on same line

开发者 https://www.devze.com 2023-01-09 19:41 出处:网络
Want to do a fancy effect by printing [OK] at the end of the last line when a task is finished. Got this:

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

精彩评论

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