Last active
June 5, 2022 15:24
-
-
Save AndersDJohnson/3068883 to your computer and use it in GitHub Desktop.
shell get download content-length
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# get download file size | |
URL=$1 | |
curl -sI "${URL}" | grep "Content-Length" | cut -d ' ' -f 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not good way to get size "cut -d' ' -f2"
SIZE="$(curl --silent --location --head --insecure "${LINK}" | grep -i '^Content-Length' | cut -d' ' -f2)"
Because if you use this for variable is will contains additional characters like this:
SIZE=$'597622784\r'
Better user grep:
SIZE="$(curl --silent --location --head --insecure "${LINK}" | grep -oP '(?i)(?<=Content-Length:\s)\d{1,20}(?=\D)?')"