Page 1 of 1

little help : convert .bat to bash script

Posted: 2019-04-09T01:24:49-07:00
by ChristianK
Hi,
I made a little script in .bat file running on windows, but I need it now in mac os X, so in bash,
but I didn't know how to convert argument in it :
the script is very simple, it compare 2 files :
@FOR /r %%I in (*.jpeg) do ("C:\Program Files\ImageMagick\magick.exe" compare %%I %%~pI%%~NI_1.jpeg %%~NI-compare.jpeg)
It compare in each subfolders the files with the name and the name_1 and then the result at the top of subfolders.

I didn't find how to translate the argument very useful with the for command in dos :
%I
%~pI
%~NI

Thanks for your help,
Christian

Re: little help : convert .bat to bash script

Posted: 2019-04-29T11:27:48-07:00
by squiddy
There are probably half a dozen different ways to do what you want in bash, and it's not entirely clear from your post what all the details of your situation are. If you are going to be working in bash in the future, you need to learn it properly. It is a much more powerful and flexible shell than Windows' shell (or even PowerShell).

It's a long time since I've had to write a DOS batch file, so I'm not clear what your "%%" variable substitutions are doing, but in principle, a bash script to do something *similar* would be like this.

Assuming that your filenames are all of the form name.jpeg and name_1.jpeg, and are all in the current (working) directory, and the magick executable is in your search path.

Code: Select all

for i in *_1.jpeg; do magick compare $i $(basename $i _1.jpeg).jpeg $i_compare.jpeg;done
there's a pretty comprehensive bash tutorial at https://tldp.org
hth

Re: little help : convert .bat to bash script

Posted: 2019-04-29T14:45:38-07:00
by fmw42
This is an imagemagick image processing forum. I think you should Google for docuemtation on bash scripting.

Your code in bash would be something like:

@FOR /r %%I in (*.jpeg) do ("C:\Program Files\ImageMagick\magick.exe" compare %%I %%~pI%%~NI_1.jpeg %%~NI-compare.jpeg)

Code: Select all

for img in path_to_directory/*.jpeg
name=`convert "$img" -format "%t" info:`
magick compare -metric rmse $img ${name}_NI_1.jpeg ${name}_NI_compare.jpeg 
done