Multi-line Syntax (cmd)

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
afre
Posts: 57
Joined: 2014-01-22T15:02:53-07:00
Authentication code: 6789

Multi-line Syntax (cmd)

Post by afre »

Continued from this discussion. snibgo, how would you make this arbitrary code more readable?

Code: Select all

FOR %j in (045 155) DO FOR %k in (050 150) DO convert rose: -resize 500% -modulate %j,%k,100 rose%j%k.png
Could easily add another loop by substituting rose: with %i for batch image processing.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Multi-line Syntax (cmd)

Post by snibgo »

As a command typed into the console, I wouldn't split it. I can't see any point in splitting it.

If in a BAT script, so each % must be doubled, I might do it like this:

Code: Select all

FOR %%j in (045 155) DO FOR %%k in (050 150) DO convert ^
  rose: -resize 500%% -modulate %%j,%%k,100 rose_%%j_%%k.png
or

Code: Select all

FOR %%j in (045 155) DO (
  FOR %%k in (050 150) DO (
    %IM%convert ^
      rose: ^
      -resize 500%% ^
      -modulate %%j,%%k,100 ^
      rose_%%j_%%k.png
  )
)
I have also put underscores _ in the output filename.

I generally split convert commands so each input, output, and unit of processing is on a separate line.
snibgo's IM pages: im.snibgo.com
afre
Posts: 57
Joined: 2014-01-22T15:02:53-07:00
Authentication code: 6789

Re: Multi-line Syntax (cmd)

Post by afre »

I do try to figure things out but could you elaborate on this?
snibgo wrote:

Code: Select all

for /F "usebackq" %%L in (`convert ^
  infile ^
  {procesing} ^
  outfile`) do {something}
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Multi-line Syntax (cmd)

Post by snibgo »

See examples in my scripts, such as http://im.snibgo.com/eqlimit.htm#eqLimit.bat
snibgo's IM pages: im.snibgo.com
afre
Posts: 57
Joined: 2014-01-22T15:02:53-07:00
Authentication code: 6789

Re: Multi-line Syntax (cmd)

Post by afre »

snibgo wrote:These days, my usual syntax is something like: for /F "usebackq" %%L in (`convert ^
....
See examples in my scripts, such as http://im.snibgo.com/eqlimit.htm#eqLimit.bat
My impression is that it pipes the output from one command to another; in your examples, it's used to ECHO results or set them to a local variable. I guess I'm also trying to figure out how it relates to my previous question regarding indentation, etc.

Anyway, this is what I was looking for, thanks.
Post Reply