0

I am using the following construct to set a multiline string in bash shell. But this always returns false which does not work when I set set -e. How can I make this to return success?

#!/bin/bash
set -x
set -e

read -d '' QUERY <<EOF
UPDATE table_name SET
 field1 = 'value',
 field2 = 'value'
 WHERE id = 1;
EOF
mysql table_name -e "$QUERY"

1 Answer 1

2

While not an answer to your original question, this does get your problem solved. Consider using substitution and e.g. cat

QUERY=$(cat <<EOM
test
test2
EOM
)

mysql table_name -e "$QUERY"

Please, be aware of safety issues if you're reading those values from unsanitized input.

Sign up to request clarification or add additional context in comments.

1 Comment

@codefx, you've unaccepted this answer. Would you care to add a comment explaining why this solution once worked and now no longer answers the question you've asked? It would be educational, not just for me, but also for others looking for a similar solution.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.