码迷,mamicode.com
首页 > 系统相关 > 详细

remove '^M' in shell script

时间:2015-08-13 12:06:29      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:shell   vi   

最近在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 '^M' in shell script

标签:shell   vi   

原文地址:http://blog.csdn.net/quincyfang/article/details/47609755

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!