Akki Akki - 1 year ago 124
Bash Question

Adding a newline to AWS SNS message in a shell script

I want to send AWS SNS notification through shell script in EC2. The following is my command:

aws sns publish --topic-arn arn:aws:sns:x:x:x \
--subject "Processing Error - ${tablename}" \
--message "An error has occurred in API data processing. The error file ${error_file} has been written to the errors folder...The file contents of ${error_file} are : $(cat ${error_file})"

My problem is that I don't know how can I insert a newline before I printing the content of file using "
" command? I want to print the content of the file after a newline. Now it gets appended to
"The file contents of ..."

How do I add a newline into the

Answer Source

Inserting the literal newline character

aws sns publish --message="...
$(cat ${error_file})" # other options

In Bash/Ksh93/Zsh:

aws sns publish --message="..."$'\n'"$(cat ${error_file})" \
  # other options

Using printf:

aws sns publish --message="$(printf "%s\n%s" "..." "$(cat ${error_file})")" \
  # other options
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download