0

I need to write a cron job, to send an mqtt message to "homie/$HOSTNAME/$state".

In the case of $HOSTNAME - it needs to use the env variable, but $state - it must use as is.

How would I add "homie/$HOSTNAME/$state" without bash thinking the $state is a variable as well?

Jéan
  • 639
  • 4
  • 11
  • 28
  • 1
    `"homie/$HOSTNAME/"'$state'` -- put the `$state` in single quotes. Or `"homie/$HOSTNAME/\$state"`, keeping it all in double quotes but putting a backslash before the character you want interpreted as literal. – Charles Duffy Apr 14 '20 at 16:48
  • The 2nd option worked for me in the ansible script I had, tx! – Jéan Apr 14 '20 at 17:01

0 Answers0