little help : convert .bat to bash script

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
ChristianK
Posts: 10
Joined: 2019-03-04T08:44:14-07:00
Authentication code: 1152

little help : convert .bat to bash script

Post 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
squiddy
Posts: 16
Joined: 2018-09-27T02:53:52-07:00
Authentication code: 1152

Re: little help : convert .bat to bash script

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: little help : convert .bat to bash script

Post 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
Post Reply