Add tail -1 before tr to use only the last value

This commit is contained in:
justin 2026-01-27 11:30:26 -05:00 committed by Michel Roegl-Brunner
parent 622fda4b32
commit 75898f4986
2 changed files with 4 additions and 4 deletions

View File

@ -201,10 +201,10 @@ download_with_progress() {
content_length=$( content_length=$(
curl -fsSLI "$url" 2>/dev/null | curl -fsSLI "$url" 2>/dev/null |
# May return multiple values on redirect. i.e., 0 and content-length # May return multiple values on redirect. i.e., 0 and actual content-length value
# Cast $2 to int by adding 0 to it # Cast $2 to int by adding 0 to it
awk '(tolower($1) ~ /^content-length:/) && ($2 + 0 > 0) {print $2+0}' | awk '(tolower($1) ~ /^content-length:/) && ($2 + 0 > 0) {print $2+0}' |
tr -cd '[:digit:]' || true tail -1 | tr -cd '[:digit:]' || true
) )
if [ -n "$content_length" ]; then if [ -n "$content_length" ]; then

View File

@ -1694,10 +1694,10 @@ function download_with_progress() {
local content_length local content_length
content_length=$( content_length=$(
curl -fsSLI "$url" 2>/dev/null | curl -fsSLI "$url" 2>/dev/null |
# May return multiple values on redirect. i.e., 0 and content_length # May return multiple values on redirect. i.e., 0 and actual content-length value
# Add 0 to $2 to cast it to int # Add 0 to $2 to cast it to int
awk '(tolower($1) ~ /^content-length:/) && ($2 + 0 > 0) {print $2+0}' | awk '(tolower($1) ~ /^content-length:/) && ($2 + 0 > 0) {print $2+0}' |
tr -cd '[:digit:]' || true tail -1 | tr -cd '[:digit:]' || true
) )
if [[ -z "$content_length" ]]; then if [[ -z "$content_length" ]]; then