编写Shell的时候发现读取win下的文件会出现文本结尾有^M,经过查找,在stackoverflow找到了答案。示例代码如下:

cat keywords.txt |while read line
do
line=${line//[$'\t\r\n']}
cdomain=$line.$domain
done

来源:https://stackoverflow.com/questions/19345872/dirty-variable-remove-carriage-return/19347380#19347380

Related Posts: Shell-逐行读入文本-变量去除换行^M,\r,\n :