summaryrefslogtreecommitdiff
path: root/head.bash
diff options
context:
space:
mode:
Diffstat (limited to 'head.bash')
-rwxr-xr-xhead.bash15
1 files changed, 14 insertions, 1 deletions
diff --git a/head.bash b/head.bash
index 9cc425d..71f8baf 100755
--- a/head.bash
+++ b/head.bash
@@ -1,5 +1,17 @@
#!/bin/bash
+function filesize {
+echo $1 | awk 'function human(x) {
+ s=" B KiB MiB GiB TiB EiB PiB YiB ZiB"
+ while (x>=1024 && length(s)>1)
+ {x/=1024; s=substr(s,5)}
+ s=substr(s,1,4)
+ xf=(s==" B ")?"%5d ":"%8.2f"
+ return sprintf( xf"%s\n", x, s)
+ }
+ {gsub(/^[0-9]+/, human($1)); print}'
+}
+
read url
arg1=`echo "$url" | cut -d\ -f1`
argrest=`echo "$url" | cut -d\ -f1 --complement`
@@ -24,7 +36,8 @@ sed -i ':a;N;$!ba;s/\r//g' head.txt
http=`grep HTTP head.txt`
modified=`grep Last-Modified head.txt | sed "s/Last-Modified: //"`
type=`grep Content-Type head.txt | cut -d " " -f2`
-length=`grep Content-Length head.txt | cut -d " " -f2 | ./filesize.sh | sed -r "s/[ \t]{2,}//"`
+length=`grep Content-Length head.txt | cut -d " " -f2`
+length=`filesize $length | sed -r "s/[ \t]{2,}//"`
if [[ ! "$http" =~ "200" ]]
then