Shell 在ZSH脚本中显示倒计时?

Shell 在ZSH脚本中显示倒计时?,shell,timeout,zsh,Shell,Timeout,Zsh,我有一个zsh脚本,从中读取用户的输入,一段时间后默认为“是” 我目前正在使用类似于read-q-tt5的东西来实现这一点。以下是实际代码: echo "${Red}Errors${RegF} were detected in the output of $i." read -q -tt $CONFIRMATION_TIMEOUT "REPLY?Proceed? [Yn] " echo case $REPLY in 'N') ;& 'n') echo "Aborting.

我有一个zsh脚本,从中读取用户的输入,一段时间后默认为“是”

我目前正在使用类似于
read-q-tt5
的东西来实现这一点。以下是实际代码:

echo "${Red}Errors${RegF} were detected in the output of $i."
read -q -tt $CONFIRMATION_TIMEOUT "REPLY?Proceed? [Yn] "
echo
case $REPLY in
    'N') ;&
    'n') echo "Aborting..."; exit 0;;
    *) ;;
esac
我得到:

Errors were detected in the output of groups.xml.
Proceed? [Yn] 
但是我想在屏幕上显示一个倒计时,可能是这样的

Errors were detected in the output of groups.xml.
Proceed? [Yn] (5)
这个数字每秒钟都在减少

我有什么办法可以做到这一点吗

谢谢大家!


PS:我也很感谢您在这段代码中对可以更好地完成的事情的评论。

您可以做如下事情:

echo "${Red}Errors${RegF} were detected in the output of $i."
{ i=$CONFIRMATION_TIMEOUT; while test $((i--)) -ge 0; do 
  printf "\rREPLY?Proceed? [Yn] ($i)"; sleep 1; done; } &

read -q -tt $CONFIRMATION_TIMEOUT
kill $!
echo
case $REPLY in
    'N') ;&
    'n') echo "Aborting..."; exit 0;;
    *) ;;
esac