你說得對,這是一個字符集問題。您需要將適當的環境變量設置到您的crontab的開頭。
像這樣的東西應該工作:
LANG=en_US.UTF-8
LC_CTYPE=en_US.UTF-8
到位LC_CTYPE的可以選擇使用LC_ALL。
參考:http://opengroup.org/onlinepubs/007908799/xbd/envvar.html
編輯:當您在shell中運行它,它顯示正常的原因可能是因爲上述ENV瓦爾在你的shell設置。
要驗證,請在shell中執行'區域設置',然後與運行相同命令的cronjob的輸出進行比較。
重新編輯:好的,所以它不是一個env var問題。
我假設你使用的是mailx,因爲它是現今最常見的。它的手冊頁說:
The character set for outgoing messages is not necessarily the same as the one used on the terminal. If an outgoing text message contains characters not representable in US-ASCII, the character set being used must be declared within its header. Permissible values can be declared using the sendcharsets variable,
所以,嘗試添加下面的參數調用郵件時:
-S sendcharsets=utf-8,iso-8859-1
我的文本是從shell腳本直接ECHO的。從控制檯執行時,特殊字符顯示正確。 – JohnWithoutArms 2010-06-25 17:51:06
電子郵件的標題顯示此內容: Content-Transfer-Encoding:7bit – JohnWithoutArms 2010-06-25 17:52:22
我正在嘗試這樣做:echo「maçã」|郵件[email protected]。 而在電子郵件上收到的結果是:ma ????。 LANG設置爲pt_BR.UTF-8,LC_CTYPE也一樣。 – JohnWithoutArms 2010-06-25 17:56:50