在 shell 脚本中向 AWS SNS 消息添加换行符

Adding a newline to AWS SNS message in a shell script

我想通过 EC2 中的 shell 脚本发送 AWS SNS 通知。以下是我的命令:

aws sns publish --topic-arn arn:aws:sns:x:x:x \
  --region=$AWS_DEFAULT_REGION \
  --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})"

我的问题是我不知道如何在使用“cat”命令打印文件内容之前插入换行符?我想在换行符后打印文件的内容。现在它附加到 "The file contents of ...".

如何在 --message 参数中添加换行符?

插入文字换行符

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

在Bash/Ksh93/Zsh中:

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

使用printf

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