shell脚本实现命令执行等待状态显示的三种方式

显示状态1-处于"/"旋转

#!/bin/sh
sleep 10 &
pid=$! # Process Id of the previous running command

spin='-\|/'

i=0
while kill -0 $pid 2>/dev/null
do
  i=$(( (i+1) %4 ))
  printf "\r[${spin:$i:1}]"
  sleep .1
done

显示状态2-进度条前进状态

#!/bin/sh
j=''
for ((i=0;$i<=100;i+=2))
do
        printf "progress:[%-50s]%d%%\r" $j $i
        sleep 0.1
        j=#$j
done
echo

显示状态3-进度条前进+处于"/"旋转

#!/bin/bash
i=0
j='#'
k=('|' '\' '-' '/')
l=0
while [ $i -le 25 ]
do
    printf "progress:[%-25s][%d%%][%c]\r" $j $(($i*4)) ${k[$l]}
    j+='#'
    let i++
    let l=i%4
    sleep 0.1
done
printf "\n"
posted @ 2020-05-22 17:54  Wolf_Dreams  阅读(10022)  评论(0编辑  收藏  举报