首页 > 系统服务 > 详细

remove '^M' in shell script

时间:2017-08-04 13:14:46      阅读:316      评论:0      收藏:0      [点我收藏+]
近期在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 "\015" <${f}> ${f}1

        echo "Back to the original file name"
        mv ${f}1 ${f}
   fi
 done
 ll --color

remove &#39;^M&#39; in shell script

原文:http://www.cnblogs.com/mthoutai/p/7284419.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!