1

I'm using convert to add text to some images via a bash script. My issue is that I can't figure out how to add the contents of the variable to the text string to be placed in the image.

My script is as follows:

#! /bin/bash
for i in {1..10}
do
    convert -font TlwgTypewriter-Bold -pointsize 18 -fill white -draw 'text 140,29 "ID: $i"' $i.png $i-reward.png
done

But when I run it I get the following:

bashimage

How might I get the variable to output its contents into this string?

1 Answer 1

4

It seems it is due to wrong quoting of your command here:

-draw 'text 140,29 "ID: $i"'

Change that to:

-draw "text 140,29 \"ID: $i\""

It is because shell doesn't expand variables inside single quote.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.