This question may sound like a duplicate, but I think it's different than the pages that I've found. I'm trying to assign the contents of a text file to a bash variable, but I want the "\n" character to be included as a string rather than actually seeing it on a new line. For example, the contents of the file look something like this:
Here is the content of the text file
There are multiple lines
blah blah blah
I want the variable "text_file" below to be assigned the contents of the file so when I use it in my script it looks like so:
Here is the content of the text file\nThere are multiple lines\nblah blah blah
I'm using this variable in the following script, and I'm getting this error, which I believe is a result of the newline characters in "hello.txt" file that I'm assigning to the variable.
Error parsing parameter '--message': Invalid JSON: Invalid control character u'\n' at:
subject="Test Email Sent Via AWS"
message="here is the message to the user...\n\n"
text_file=`cat hello.txt`
full_message="$message$text_file"
cat <<EOF > generated_message.json
{
"Subject": {
"Data": "$subject",
"Charset": "UTF-8"
},
"Body": {
"Text": {
"Data": "$full_message",
"Charset": "UTF-8"
}
}
}
EOF
aws ses send-email --profile sendmail --from blah@email.com --destination file://destination.json --message file://generated_message.json
I think I'm missing something basic, but I can't figure it out. Thanks in advance for the help.