Re: Command substitution into argument to convert

Lewis <[email protected]> Tue, 14 Jun 2022 00:21:04 -0000 (UTC)
Newsgroups alt.comp.lang.shell.unix.bourne-bash
Organization Miskatonic U
Message-ID <[email protected]>
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

> 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.


> 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.

-- 
I presume you're mortal, and may err.