image processing - Shell script with args, where the args are files with spaces -


i wish use shell script accepts loop of directory imagemagick script. shell script this:

#!/bin/sh # ~/scripts/mkhdr.sh  convert -gaussian $1 $2 - | composite -compose overlay $2 - $3 

and loop thus:

for in *.(tif|jpg);do;echo converting $i;~/scripts/mkhdr.sh 3 ./$i ./ssp_jpgs/$i:r.jpg;done 

works fine on directory of files without spaces. fails on directory files names contains spaces.

update:

thanks adrian frühwirth, here's works:

#!/bin/sh # ~/scripts/mkhdr.sh  convert -gaussian "$1" "$2" - | composite -compose overlay "$2" - "$3" 

command line:

for file in *.(tif|jpg);do;echo converting "${file}";~/scripts/mkhdr.sh 3 "${file}" "/users/me/desktop/${file}";done 

there several things wrong both snippets posted. let's start second:

for in *.(tif|jpg);     echo converting $i     ~/scripts/mkhdr.sh 3 ./$i ./ssp_jpgs/$i:r.jpg done 
  1. as pointed out, need quote variables account spaces in filenames.
  2. i not familiar zsh's :r syntax, since searching .jpg , .tif files :r.jpg not account .tif files.

now first snippet:

#!/bin/sh # ~/scripts/mkhdr.sh  convert -gaussian $1 $2 - | composite -compose overlay $2 - $3 

even if quote variables in other snippet, unquoted here , once again, filenames spaces problem.

now let's apply fixes, starting conversation snippet:

#!/bin/sh # ~/scripts/mkhdr.sh  convert -gaussian "$1" "$2" - | composite -compose overlay "$2" - "$3" 
  • always quote variables on safe side.

and calling snippet:

for file in *.tif *.jpg;         echo "converting '${file}'"         ~/scripts/mkhdr.sh 3 "${file}" "./ssp_jpgs/${file%.*}" done 
  • quoted variables.
  • changed *.(tif|jpg) syntax *. tif *.jpg. should work in zsh, bash , ksh93, don't have use this.
  • changed $i:r.jpg ${i%.*}. removes shorted match of .* of value of i, happens file extension. should work in zsh, bash , ksh93.

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -