Issues executing a 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
coldkingnowhere
Posts: 7
Joined: 2011-11-01T13:36:39-07:00
Authentication code: 8675308

Issues executing a bash script

Post by coldkingnowhere »

This is my first time using imagemagick or even Unix-style scripts for that matter so feel free to berate me for stupid mistakes.

I am using Cygwin in Windows 7 to make this work. When I try to execute the .sh file posted below, I get a number of errors. I am simply trying to edit all the .png files in my home folder and then move the edited files to another folder. Any help (and of course, your patience with a luddite) is greatly appreciated.

Errors:
./IM_hero.sh: line 2: $'\r':command not found
./IM_hero.sh: line 3: syntax error near unexpected toke '$'\r' '
./IM_hero.sh: line 3: 'for f in *.png;

Code: Select all

#!/bin/bash

for f in *.png;
do
	echo "Processing $f"
	convert	-set density 38 -units PixelsPerCentimeter \
		-bordercolor white -border 1x1 \
        -alpha set -channel RGBA -fuzz 3% \
        -fill none -floodfill +0+0 white \
        -shave 1x1 \
		-blur 0x.3 \
		-trim +repage \
		-resize 230x375 \
			$f ./edited_images/$f
done
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Issues executing a bash script

Post by Bonzo »

Why not use a batch file for this?

Something along the lines of this old example:

Code: Select all


::Turn of displaying the code on the screen
 @echo off
 
:: Read all the jpg images from the directory, resize them, add some text and save as a png in a different directory
 for %%f in (%1\*.jpg) do ( convert "%%f" -resize 200x200 -pointsize 18 -fill black ^
 -gravity northwest -annotate +0+0 "Some text" "%2\%%~nf.png" )

This batch file was named resize.bat in C and called using "resize path\to\original\ path\to\save"
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Issues executing a bash script

Post by el_supremo »

It looks like the shell file you are using has DOS line endings which might be causing the problems with '\r'.
Can you convert the file so that it has only linefeeds ('\n') at the end?

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
coldkingnowhere
Posts: 7
Joined: 2011-11-01T13:36:39-07:00
Authentication code: 8675308

Re: Issues executing a bash script

Post by coldkingnowhere »

You were right about the line endings. It all works fine now. Thank you!
Post Reply