【问题标题】:Using bash variable in text output在文本输出中使用 bash 变量
【发布时间】:2014-08-02 18:22:13
【问题描述】:

我正在使用 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

但是当我运行它时,我得到以下信息:

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

【问题讨论】:

    标签: bash variables imagemagick-convert


    【解决方案1】:

    这似乎是由于在这里错误地引用了您的命令:

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

    将其更改为:

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

    这是因为shell没有在单引号内展开变量。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-30
      • 2021-11-04
      • 1970-01-01
      • 2021-10-03
      • 2012-08-16
      • 1970-01-01
      相关资源
      最近更新 更多