#!/bin/bash#Name:copyprogess#Author:hongyu#Desc:#Usage:#Path:/home/hongyu/bin#Update:Wed 22 Jul 2020 09:38:37 AM UTCdraw_bar(){local cur=$1local all=$2let local speed=(cur*100)/alllocal fonts=\"#\"let local count=speed-1[[ $((count%2)) -eq 1 ]]&&let count++local str=$(for i in $(seq 1 $((count/2)));do printf \"%s\" \"$fonts\";done)printf \"\\033[?25l\\033[37m\\033[1m[%-50s] %d%%\\033[?25h\\033[0m\\r\" \"$str\" \"$speed\";sleep 0.01}Copyfucntion(){cp -r $1 $2 &file_all=$(du -s $1 | egrep -o \"^\\w+\")while :dofile_old=$(du -s $2 | egrep -o \"^\\w+\")draw_bar $file_old $file_alllet tmp=file_all-file_oldif (( tmp - old == 0 ))thenlet file_old=file_old+tmpdraw_bar $file_old $file_allbreakfilet old=tmpif (( tmp == 0 ))thenbreakfidoneecho}RecordArgv(){argv=$*let args=$#-1let i=0for record in $argvdolet i++if (( i < $args ))thenmv $record $direlif (( i == $args ))thenecho $recordfidone}if (( $# == 2 ))thenCopyfucntion $1 $2elsedir=tempif [ -d $dir ]thenecho \"is exit\" > /dev/nullelsemkdir $dirfiTarget=$(RecordArgv $* $#)Copyfucntion $dir $Targetcd $dirmv * ../cd ../rm -rf $dirfi
shell cp进度条改良版
未经允许不得转载:爱站程序员基地 » shell cp进度条改良版