Re: Command substitution into argument to convert

"Michael F. Stemper" <[email protected]> Tue, 14 Jun 2022 07:59:18 -0500
Newsgroups alt.comp.lang.shell.unix.bourne-bash
Organization A noiseless patient Spider
Message-ID <[email protected]>
On 13/06/2022 19.21, Lewis wrote:
> In message <[email protected]> Michael F. Stemper <[email protected]> wrote:
>> I'm trying to time-stamp image files as they're downloaded. The
>> following works fine:
> 
>> $ convert -pointsize 20 -fill black -draw 'text 10,20 "06/13 14:13"' RadarMap.png Stamped.png
> 
>> However, hard-coding the time stamp would make it worthless. What
>> I really want to use is the output of:
> 
>> $ date +"%m/%d %H:%M"
> 
> So do that.
> 
> $ MYDATE=$(date +"%m/%d %H:%M");convert -pointsize 20 -fill black -draw 'text 10,20 "$MYDATE"' RadarMap.png Stamped.png

No error message is given. The text drawn on the image is:
   $MYDATE

> 
>> For instance,
> 
>> $ convert -pointsize 20 -fill black -draw 'text 10,20 $(date +"%m/%d %H:%M")' RadarMap.png Stamped.png
> 
> Notice that you have changed the quotes since you have "" inside '' in
> your original. You would need to figure out the escaping to make this
> right. Setting a variable avoids this.
> 
> 
>> $ convert -pointsize 20 -fill black -draw "text 10,20 $(date +"%m/%d %H:%M")" RadarMap.png Stamped.png
> 
> same issue, you are not quoting the way the original command is quoted.

This is true. I have tried several different ways of quoting. None
of them have worked for me.

>> I've even tried two steps, initializing a variable and using it:
> 
>> $ ts=$(date +"%m/%d %H:%M")
>> $ echo $ts
>> 06/13 14:24
>> $ convert -pointsize 20 -fill black -draw "text 10,20 $ts" RadarMap.png Stamped.png
> 
> Your original line has 'text 10,20 "the date is here"'
> 
> Note the quotes.

And when I put single quotes around the text directive, I get:

$ ts=$(date +"%m/%d %H:%M")
$ convert -pointsize 20 -fill black -draw 'text 10,20 $ts' RadarMap.png Stamped.png
convert: non-conforming drawing primitive definition `ts' @ error/draw.c/DrawImage/3190.
$


-- 
Michael F. Stemper
A preposition is something you should never end a sentence with.