Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send special characters via mail from a shell script?

Tags:

I have a script that runs on cron that outputs some text which we send to the 'mail' program. The general line is like this:

./command.sh | mail -s "My Subject" [email protected] -- -F "Sender Name" -f [email protected] 

The problem is that the text generated by the script has some special characters - é, ã, ç - since it is not in english. When the e-mail is received, each character is replaced by ??.

Now I understand that this is most likely due to the encoding that is not set correctly. What is the easiest way to fix this?

like image 747
JohnWithoutArms Avatar asked Jun 25 '10 17:06

JohnWithoutArms


People also ask

How do you pass special characters in Linux?

In a shell, the most common way to escape special characters is to use a backslash before the characters. These special characters include characters like ?, +, $, !, and [. The other characters like ?, !, and $ have special meaning in the shell as well.

How do you print special characters in shell?

The backslash (\) character is used to mark these special characters so that they are not interpreted by the shell, but passed on to the command being run (for example, echo ). So to output the string: (Assuming that the value of $X is 5): A quote is ", backslash is \, backtick is `. A few spaces are and dollar is $.

How do I email a shell script output?

Run `mail' command by '-s' option with email subject and the recipient email address like the following command. It will ask for Cc: address. If you don't want to use Cc: field then keep it blank and press enter. Type the message body and press Ctrl+D to send the email.

Is special character in shell script?

The characters <, >, |, and & are four examples of special characters that have particular meanings to the shell. The wildcards we saw earlier in this chapter (*, ?, and [...]) are also special characters. Table 1.6 gives the meanings of all special characters within shell command lines only.


1 Answers

My /usr/bin/mail is symlinked to /etc/alternatives/mail which is also symlinked to /usr/bin/bsd-mailx

I had to specify myself the encoding in the mail header. (The -S is not supported here.)

cat myutf8-file | mail -a "Content-Type: text/plain; charset=UTF-8" -s "My Subject" [email protected]

like image 63
KumZ Avatar answered Jan 26 '23 18:01

KumZ