Page 1 of 1

Issues executing a bash script

Posted: 2011-11-01T13:49:25-07:00
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

Re: Issues executing a bash script

Posted: 2011-11-01T14:34:20-07:00
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"

Re: Issues executing a bash script

Posted: 2011-11-01T14:48:49-07:00
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

Re: Issues executing a bash script

Posted: 2011-11-01T15:26:40-07:00
by coldkingnowhere
You were right about the line endings. It all works fine now. Thank you!