Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've generated a shell script that uses ImageMagick to convert and crop around 18000 images. Here's a sample entry (so there are 18000 of these):

if [ ! -f ./cropped/16333-1.png ]
convert -crop 724x118+876+1989 ./lin/34.png ./cropped/16333-1.png
echo cropping 16333-1
if [ ! -f ./cropped/16333-1_thumb.png ]
convert -define jpeg:size=400x100 ./cropped/16333-1.png -thumbnail '400x100>' -background transparent -gravity center -extent 400x100 ./cropped/16333-1_thumb.png
echo thumbing 16333-1

The script only runs for about 2000 images before hanging forever. Am I missing something, or leaking memory somewhere?

Thanks for your help!


I tried running the script with the -x flag as suggested, and the script hung after this command:

+ '[' '!' -f ./cropped/8967-1_thumb.png ']'
+ convert -define jpeg:size=400x100 ./cropped/8967-1.png -thumbnail '400x100>' -background transparent -gravity center -extent 400x100 ./cropped/8967-1_thumb.png

However, when I interrupt the script and then copy and paste the command above, it runs just fine. No hanging. I can then resume the script, and it sets off again fine.


share|improve this question

My guess is that there's some shell meta character in there somewhere which is tripping it up.

To diagnose and solve:

  1. Identify exactly where it stops
  2. Look at the ten lines around it
  3. Look for any > < ! $ which aren't escaped

Alternately, add -x to the first line of the script so that you can see each command as it's run. It should look something like:

#! /bin/bash -x
share|improve this answer
I agree. It sounds like the script was generated from a list of filenames, so the problem may originate from a funny character (><!$ as you say, or maybe even just a space) in a filename. The +x option should make this much easier to diagnose. – Gordon Davisson Dec 29 '10 at 16:48
Thanks! You're right that it was generated (from a range of numbers, not from a list of filenames). However when I try using the -x flag, it seems to fail on a command that then works OK. Please see update. – AP257 Dec 29 '10 at 17:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.