我编写了一个小脚本来获取一些网址
#!/bin/bash
input_file="urls.txt"
function convert_to_bpp
{
local filesize=$1
local bpp
bpp=$(echo "(($filesize * 8) / ($width * $height))" | bc -l)
printf -v bpp "%0.2f" "$bpp" #set to 2 dp
echo "$bpp"
}
image_count=0
images_names=()
while read -r url && [[ "$image_count" -le 10000 ]]; do
wget "$url"
filename=$(basename "$url")
width=$(identify -format "%w" "$filename")
height=$(identify -format "%h" "$filename")
new_size=$(wc -c < "$filename")
new_size_bpp=$(convert_to_bpp "$new_size")
if (( $(echo "$new_size_bpp > 8" |bc -l) )); then
echo "$url" >> hq_urls.txt
image_count=$(( image_count + 1 ))
images_names+=("$filename")
echo "$image_count"
else
rm -rf "$filename"
fi
done < "$input_file"
zip "quality_images.zip" "${images_names[@]}"
bash -n getimages.sh
getimages.sh: line 8: syntax error near unexpected token `}'
getimages.sh: line 8: `}'
我已使用Shellcheck检查脚本并使用dos2unix
,但他们无法检测到错误。
GNU bash, version 4.1.2(2)-release (x86_64-redhat-linux-gnu)