这个shell脚本通过在一个GTK+对话框(使用小巧方便的对话框工具zenity,下载地址是http://download.chinaunix.net/download/0013000/12216.shtml),来显示文件下载了百分之多少(%)。当我们在命令行下使用shell命令,比如用wget下载文件再配合这个脚本将是非常有用的。
相信该shell脚本是很有帮助的,代码如下:
#!/bin/sh #http://hektor.umcs.lublin.pl/~mikosmul/computing/shell-scripts/view-download-progress # Written by Michal Kosmulski <mkosmul _at_ users _dot_ sourceforge _dot_ net> # This script is hereby put in the public domain. # Display a dialog box with a progress bar showing how much of a file # has been downloaded. # Parameters: # $1 file name # $2 final file size (in bytes) # Uses zenity if [ $# != 2 ]; then echo "Usage:" echo "$0 file_name final_size" exit 1; fi name="$1" final_size="$2" size=0 ( while (( size < final_size )); do if [ -f "$name" ]; then size=`ls -l "$name" | awk '{print $5}'`; else size=0 fi echo -e '#'"${name}: ${size} of ${final_size}"; echo -e "100*${size}/${final_size};\nquit\n" | bc; sleep 1; done echo '#'"${name}: Finished downloading - ${size} of ${final_size}"; ) | zenity --title="Downloading file ${name}" --progress --percentage=0 |