Bash文件测试条件

时间:2012-07-22 11:17:38

标签: bash conditional

我正在使用Hugin工具集的命令行版本生成全景图。在执行脚本时,所有图像被分类到由单个全景图组成的n个图像的文件夹中。根据混合过程的执行情况,可能会产生以下两个文件名之一:pano.tifpano_blended_fused.tif

无论生成哪个文件,我都希望将该文件转换为jpg并调整大小。我目前的代码是

dirlist=$(find . -mindepth 1 -maxdepth 1 -type d \( ! -name completed \) | sort -n)
for dir in $dirlist
do
    #pano generating gode goes here


  #Downsize and convert panorama
  #######################################################################
  tifImage=
  jpgImage=

  if [ -e "pano.tif" ]; then
    tifImage="pano.tif"
    jpgImage="pano.jpg"
    echo "Working on pano.tif"
    echo ""

  elif [ -e "pano_blended_fused" ]; then
    tifImage="pano_blended_fused.tif"
    jpgImage="pano_blended_fused.jpg"
    echo "Working on pano_blended_fused.tif"
    echo ""
  fi

  #convert pano to jpg and get count of images in photo folder
  echo ""
  echo "Converting $image to jpg and creating two versions"
  echo ""
  mogrify -format jpg $tifImage >> "$imagePath/$dir/log.txt"

  num=$(ls -l "$webPath/photos" | wc -l) 
  prefix=$((num+1))

  #convert full size pano to 1000 pixels high and rename with prefix number
  #move to /photos folder
  convert $jpgImage -geometry x1000 "$prefix-pano.jpg" >> "$imagePath/$dir/log.txt"
  mv "$prefix-pano.jpg" "$webPath/photos" >> "$imagePath/$dir/log.txt"

  #convert full size pano to 600 pixels wide and rename with prefix number
  #move to /thumbs folder
  convert $jpgImage -geometry 600x "$prefix-pano.jpg" >> "$imagePath/$dir/log.txt"
  mv "$prefix-pano.jpg" "$webPath/thumbs"  >> "$imagePath/$dir/log.txt"


done

昨晚我刚刚拍了一批照片,在要生成的15张全景照片中,只有9张照片进入了目的地文件夹。所有其他人在第一个convert命令时发出错误,指出n-pano.tif变量应该是$tifImage

时缺少图像文件名pano_blended_fused.tif

我需要做什么才能使pano_blended_fused图片完成转换过程?

1 个答案:

答案 0 :(得分:2)

您忘记包含完整的文件名,但缺少扩展程序:

elif [ -e "pano_blended_fused" ]; then

VS

elif [ -e "pano_blended_fused.tif" ]; then

因此,变量从未改变,convert没有得到它想要的东西。