remove '^M' in shell script

近期在windows上编辑一些shell脚本后上传到交换机框体上。
但这些shell脚本无法运行,每一行结尾都有'^M',同一时候框体上又没有dos2unix工具。
这么多脚本也不可能一行一行来改动。于是就自己写了一个脚本来把当前文件夹下全部文件里的'^M'去掉。

#!/bin/sh
filename='ls'

for f in ${filename};do
    if [ -f ${f} ]; then
        echo "delete '^M' and rename file to ${f}1"
        tr -d "15" <${f}> ${f}1

        echo "Back to the original file name"
        mv ${f}1 ${f}
   fi
 done
 ll --color
原文地址:https://www.cnblogs.com/mthoutai/p/7284419.html