Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
bash中意外标记附近的语法错误_Bash_Unix - Fatal编程技术网

bash中意外标记附近的语法错误

bash中意外标记附近的语法错误,bash,unix,Bash,Unix,我编写了一个小脚本来获取一些URL #!/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 i

我编写了一个小脚本来获取一些URL

#!/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[@]}"
我已经用
dos2unix
检查了脚本,但是他们没有检测到错误


gnubash,版本4.1.2(2)-发行版(x86\u 64-redhat-linux-GNU)

我无法复制这个。你能把你的帖子中的脚本复制到一个新的文件中并验证它是否仍然存在问题吗?顺便说一句,如果你没有编写
函数convert_to_bpp{
而是编写
convert_to_bpp(),那么你的代码就不会与其他shell完全不兼容了{
--函数关键字是bash采用的ksh扩展,不是POSIX sh标准的一部分。也就是说,这个问题在这里给出的代码中是不可复制的--请在bash 4.4.12(1)上的测试OK中看到您的函数在没有任何更改的情况下完美运行-如果此脚本有多个版本,请释放可能导致混淆的内容。如果运行
getimages.sh
,它将使用
$PATH
查找脚本,其中可能不包括当前目录。如果使用
bash-n getimages.sh
它将在当前目录中查找脚本。我无法重新编写脚本归纳一下。你能把你帖子中的脚本复制到一个新文件中,并验证它是否仍然显示问题吗?顺便说一句,如果你不写
函数convert_to_bpp{
而写
convert_to_bpp(),那么你的代码与其他shell的不兼容就会少一些{
--函数关键字是bash采用的ksh扩展,不是POSIX sh标准的一部分。也就是说,这个问题在这里给出的代码中是不可复制的--请在bash 4.4.12(1)上的测试OK中看到您的函数在没有任何更改的情况下完美运行-如果此脚本有多个版本,请释放可能导致混淆的内容。如果运行
getimages.sh
,它将使用
$PATH
查找脚本,其中可能不包括当前目录。如果使用
bash-n getimages.sh
它将在当前目录中查找脚本。
getimages.sh: line 8: syntax error near unexpected token `}'
getimages.sh: line 8: `}'