I'm try use the AWS CLI to send an SES email, but this question is more related to Bash variables, IFS, and expansion than anything AWS related.
My recipients variable is formatted as follows:
TO="\"My Name<name@email.com>\" \"Your Name<you@email.com>\""
The --to
parameter expects a space delimited list. If I don't use the $TO
variable and just do
aws ses send-email --to "My Name<name@email.com>" "Your Name<you@email.com>"
everything works just fine. But if I do any of the following, I get errors from either the --to
parameter treating $TO
as a single string or splitting on the spaces in the "name" of the recipient:
aws ses send-email --to "$TO"
aws ses send-email --to $(echo "$TO")
aws ses send-email --to "$(echo "$TO")"
sed ses send-email --to "$(echo $TO)"
How do I get the --to
parameter to treat my variable as a space delimited list but still respect the quotes wrapping each email address?
EDIT:
This is running in a docker container where I'm getting arguments passed in as strings, one of them is -email \"My Name<name@email.com>\"
where the argument to email could be 1 or many email addresses. I'm isolating the email addresses like this:
if [[ "$ITEM" =~ ^-email[[:space:]]+(.*)$ ]]; then
EMAIL=("${BASH_REMATCH[1]}")
fi
In that context, the $EMAIL variable is a single string, which doesn't lend itself well to the use arrays approach. If I do
if [[ "$ITEM" =~ ^-email[[:space:]]+(.*)$ ]]; then
EMAIL=($(echo ${BASH_REMATCH[1]}"))
fi
Then email ends up as an array with the string separated by spaces, so it breaks up the parts inside the embedded quotes. Thus, were I to set the $TO
variable manually, then no problem, but since it's coming in as a parameter, I think this is more complicated. I do have the ability to specify the delimiter that should be use between email addresses if that might make it easier to parse? Maybe read the whole argument as a string and then split it on the special delimiter like a comma to get it into an array? Or make the delimiter the " "
pattern?