1. Code 1
#! /Bin/sh
# Output "." progress bar function, compatible with bsh, KSh, and bash
# First Trap 1 2 3 15 signal, important
Trap 'Kill $ bg_pid; ECHO; exit '1 2 3 15
Function dots
{
Stty-echo>/dev/null 2> & 1
While true
Do
Echo-e "./C"
Sleep 1
Done
Stty echo
Echo
}
#---------------------------------------------
# Start the main program
#---------------------------------------------
# First run the dots function in the background
Dots &
Bg_pid = $!
# Start the program subject. In this example, sleep for 10 seconds
# Note that when necessary -- 8
2. Code 2
#! /Bin/sh
Abort (){
Printf "/033 [M/N"
Exit
}
# Donothing, justsimulatetimeconsume.
Idle (){
I = 1
Sum = 'date + % s'
Sum = 'expr $ sum/* $ sum | cut-B1'
Sum = 'expr $ sum/* 10'
While [$ I-Le $ sum]
Do
I = 'expr $ I + 2'
Trap abort 2
Done
}
Proc (){
Begin = $1
End = $2
Row = $3
Pos1 = 'expr $ begin + 1'
Pos2 = 'expr $ end-1'
Mid = 'echo "($ begin + $ end)/2-2" | bc'
Printf "/033 [2j"
Printf "/033 [$ {row}; $ {begin} H ["
Printf "/033 [$ {row}; $ {end} H]"
Echo ########################## $ pos1-Le $ pos2
While [$ pos1-Le $ pos2]
Do
Pro = 'echo "scale = 0; ($ pos1-$ begin) * 100/($ pos2-$ begin)" | bc'
If [$ pos1-GT $ mid]
Then
Printf "/033 [7 m/033 [$ {row}; $ {mid} h $ pro %/033 [$ {row}; $ {pos1} H :"
Else
Printf "/033 [m/033 [$ {row}; $ {mid} h $ pro %/033 [7 m/033 [$ {row }; $ {pos1} H :"
Fi
Pos1 = 'expr $ pos1 + 1'
Idle
Trap abort 2
Echo ####################### $ pos1-Le $ pos2
Done
Printf "/033 [M/N"
Echo "done"
}
Printf "### proc1 100 10 ### hit enter to continue"
If read a; then
Proc 1 100 10
Fi