0

I have a query string (stored in $QUERY_DISCREPANCIES) such as:

SELECT (field_a * 100) / 2
FROM ...

I am attempting to add the executed query into an email that I send out. The email template contains a row with <QUERY>. However when I use String substitution as follows:

email=${email/<QUERY>/${QUERY_DISCREPANCIES}

then my HTML output is similar to:

my_file.sh query_test.sql templates test 100),2)

Seems that when substituting the * character, it's not properly escaping it.

Not sure if I can continue to use string substitution, or if I have to resort to something more sophisticated. Help appreciated, my attempts using sed were not very successful.

mmenschig
  • 1,088
  • 14
  • 22
  • 3
    How are you later using the variable `$email`? Seems like you are missing double quotes around some expansion :) – PesaThe Jun 24 '18 at 20:01
  • @PesaThe Oh wow! That worked! I just pass $email into a function that runs mutt to send an email. I just echoed `"$email"` and it is not escaping anything. Thanks so much – mmenschig Jun 24 '18 at 20:04
  • 2
    @mmenschig Try running your script through [shellcheck.net](http://www.shellcheck.net) -- there are a bunch of gotchas like this, and it's pretty good at spotting the common ones. – Gordon Davisson Jun 24 '18 at 20:11

0 Answers0