我已经使用自动应用程序创建了通过双击运行的)。它运行命令,逐个执行命令。每个命令都需要2-3分钟。我想要实现的是在每个命令完成后显示百分比进度。

在上面的图像百分比总是为零。我希望在每个命令完成后显式地设置进度。我也知道这是可以使用AppleScript的,但是我想用bash脚本来实现。
发布于 2019-07-10 12:52:05
我这样做一次是为了我的剧本:
progress() {
set -- "$@" "$((100*$1/$2))" "$(($1 == 0 ? -1 : SECONDS*($2-$1)/$1))"
printf "%d of %d (%d%%) eta %s sec" "$@"
}传递给它两个参数:
您的脚本将如下所示:
#!/bin/bash
progress() {
set -- "$@" "$((100*$1/$2))" "$(($1 == 0 ? -1 : SECONDS*($2-$1)/$1))"
printf "%d of %d (%d%%) eta %s sec" "$@"
}
n=10 # you need to hardcode this, the total number of commands to run
i=0
command_01; progress $((++i)) $n
command_02; progress $((++i)) $n
command_03; progress $((++i)) $n
command_04; progress $((++i)) $n
command_05; progress $((++i)) $n
command_06; progress $((++i)) $n
command_07; progress $((++i)) $n
command_08; progress $((++i)) $n
command_09; progress $((++i)) $n
command_10; progress $((++i)) $n
printf "\nThat took %d sec\n" $SECONDShttps://stackoverflow.com/questions/56969949
复制相似问题