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
- as pointed out, need quote variables account spaces in filenames.
- 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 inzsh
,bash
,ksh93
, don't have use this. - changed
$i:r.jpg
${i%.*}
. removes shorted match of.*
of value ofi
, happens file extension. should work inzsh
,bash
,ksh93
.
Comments
Post a Comment