在文本输出中使用bash变量

时间:2014-08-02 18:22:13

标签: bash variables imagemagick-convert

我使用转换通过bash脚本向一些图像添加文本。我的问题是,我无法弄清楚如何将变量的内容添加到要放置在图像中的文本字符串中。

我的脚本如下:

#! /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

但是当我运行它时,我得到以下内容:

bashimage

如何让变量将其内容输出到此字符串中?

1 个答案:

答案 0 :(得分:4)

这似乎是由于你的命令错误引用:

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

将其更改为:

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

这是因为shell不会在单引号内扩展变量。