The shell script output
The shell script source code$./meter.sh27 % |======================> |
$cat ./meter.sh
#!/bin/ksh#Given start number and end number, display progress meter and percentage like wget's stylestart=1#end=333end=33scale=$(($end/100.0))for i in {$start..$end}dom1=$(($i / $scale)); m2=$(( ($end - $i ) / $scale ))integer m1; integer m2#fill 2 segments of variable length with zerosstr=$( printf "%0${m1}d %s %0${m2}d\n" 0 ">" 0 )str="|$str|"#replace first segment zeros with '=' 2nd segment zeros with space then re-joinstr1=$(echo $str | awk -F' > ' '{ print $1 }'); str1=${str1//0/=}str2=$(echo $str | awk -F' > ' '{ print $2 }'); str2=${str2//0/' '}str="${str1}>${str2}"pct=$(($i * 100 / $end ))#Beautify the final loop[ $i -eq $end ] && str=$(echo $str | sed -e 's/ /=/g' -e 's/>/=/g' -e 's/0/=/g' )print -n " \\r ${pct} % $str "sleep 1doneprintf "\n"
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.