为什么我的bash脚本无法正常工作?

时间:2019-10-15 05:40:13

标签: arrays bash grep

我编写了以下bash脚本,用于使用文件config.xml调整图像(icon.png)的大小,该文件包含必要的图像大小和用于保存调整大小的文件的链接。

n

我收到以下错误:“第9行:$ 1:歧义重定向”

如果检查数组,则会得到以下输出:

#!/usr/bin/env bash
function help {
  echo "For running the program, please write"
  echo "1) config.xml file's location containing image sizes and links for saving resized images;"
  echo "2) a name of an image to be resized."
}

function resize {
  array=()
  while read -r line
  do
    case $line in *icon*) array+=("$line");; esac
  done < $1
  for ((a=0; a < ${#array[*]}; a++))
  do
    echo "$a: ${array[$a]}"
    imagesize=$(echo "$a: ${array[$a]}" | grep "<icon"| grep -E -o "height=\"(\d+)" | grep -E -o "\d+")
    imagelink=$(echo "$a: ${array[$a]}" | grep "<icon"| grep -E -o "[^\"\'=[:space:]]+\.(jpe?g|png|gif)")
    echo $2 -resize $imagesizex$imagesize! ../../$imagelink
  done
  echo "Resizement has been executed"
}

if [ ! -f "$1" ] || [ ! -f "$2" ]
then
  help
else
  resize
fi

我只有一行而不是行列表。

能否请您帮助我使代码正常工作?另外,我想知道为什么脚本不正确。

0 个答案:

没有答案
相关问题