I'm trying to send this content using mailx command in bash script. I could see spaces between each lines. How should I remove spaces between each line and the content to look in good format?
echo "Hello there,
Please find the attachment.
Email content is having spaces between the lines. I want the spaces to be removed.
Thanks"| mailx -s "Test Email" "${attachments[@]}" "[email protected]""
Any guidance please.
Mailx command
echo "Hello there,
Please find the attachment.
Email content is having spaces between the lines. I want the spaces to be removed.
Thanks"| mailx -s "Test Email" "${attachments[@]}" "[email protected]""
I want the email content to be well formatted. Thanks!
CodePudding user response:
To remove the spaces between the lines in the email content, you can use the tr command to convert the spaces to newlines. You can do this by modifying your script as follows:
Copy code echo "Hello there, Please find the attachment. Email content is having spaces between the lines. I want the spaces to be removed. Thanks" | tr -s ' ' '\n' | mailx -s "Test Email" "${attachments[@]}" "[email protected]" The tr command stands for "translate," and it allows you to translate or delete characters in a string. The -s option specifies that repeated characters should be squeezed together, and the ' ' and '\n' arguments specify that spaces should be translated to newlines.
This should remove the spaces between the lines in the email content and format the email in a more readable way.