我目前正在编写一个 bash 脚本来自动执行任务。在我的脚本中,我希望它在执行任务时显示进度消息。
例如:
user@ubuntu:~$ 配置一些东西
->
配置一些东西。
->
配置一些东西..
->
配置一些东西...
->
配置一些东西......完成
所有进度消息都应该出现在同一行。到目前为止,以下是我的解决方法:
echo -n "Configure something "
exec "configure something 2>&1 /dev/null"
//pseudo code for progress message
echo -n "." and sleep 1 if the previous exec of configure something not done
echo " done" if exec of the command finished successfully
echo " failed" otherwise
exec 会等待命令完成,然后再继续执行脚本行吗?如果是这样,那么我如何在执行配置某事的同时回显消息?我如何知道 exec 何时完成上一个命令并返回 true?使用$?
?