有一個shell腳本(bash),用於檢查csv文件中與模式不匹配的行併發送錯誤行的郵件。這工作正常,但結合了錯誤的行linux給\ r作爲換行符,在電子郵件中沒有換行符。所以我嘗試發送\ r \ n作爲換行符,但這不起作用,perl或bash刪除這個\ n換行符。如何從shell腳本中獲得電子郵件的換行符?
這裏是一個最小的工作腳本爲例:
SUBJECT="Error while parse CSV"
TO="[email protected]"
wrongLines=$(perl -ne 'print "Row $.: $_\r\n" if not /^00[1-9]\d{4,}$/' $file)
MESSAGE="Error while parse following Lines, pattern dont match: \r\n $wrongLines"
echo $MESSAGE |od -c
OD的輸出是:
0000000 E r r o r w h i l e p a r s
0000020 e f o l l o w i n g L i n e
0000040 s , p a t t e r n d o n t
0000060 m a t c h : \ r \ n R o w
0000100 2 : 4 9 2 7 8 3 8 7 4 3 \r R
0000120 o w 3 : 4 8 2 3 2 8 9 7 3 8
0000140 \r \n
0000143
但是,什麼是,在OD輸出的行之間的\ n是原因刪除嗎?我也嘗試\ x0D \ x0A而不是\ r \ n,但這也無濟於事。有什麼建議麼?
使用更多的引號:'echo「$ MESSAGE」'。你不想要'\ r'。 –
也許你應該閱讀[echo'手冊頁](http://man7.org/linux/man-pages/man1/echo.1.html)?或者使用['printf'](http://man7.org/linux/man-pages/man1/printf.1.html)? –
@gniourf_gniourf序列'\ r \ n'是許多基於文本的協議中的標準換行符。 –