![ea14238a9512add3fd36dd7791a047f7.png](https://i-blog.csdnimg.cn/blog_migrate/272ee6967b93f218ca7e6f5d8ab857f0.jpeg)
前言
后台运行程序有一种需求,比如查看当前进度,想在终端看到某个值的变化情况:
先提供一种很土的办法,把进度落地文件为 例如 process,采用创建写的方式。然后可以使用watch -n 1 cat process来查看进度。
这里提供两种方式,python和shell
shell版本,如下(附带一个进度条的例子)
#! /bin/bash
for ((i=0; $i<=100; i+=1))
do
printf "progress: [%-100s] %d%%r" "xxxxxxxxxx xxx xxx" $i
sleep 1
done
function sleepPrograss(){
[ $# -eq 0 ] && echo "sleepPrograss Usage: sleepPrograss 10 "
[ $# -eq 0 ] && return 1
allTime=$1
strDone=''
stepTime=$(echo "scale=1; $allTime/100" | bc)
for ((i=0; $i<=100; i+=1))
d