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 "\015" <${f}> ${f}1

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

remove '^M' in shell script

时间: 2024-08-25 08:11:33

remove &#39;^M&#39; in shell script的相关文章

remove &#39;^M&#39; 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 -

[Linux Command Line and Shell Scripting Bible] basic shell script

1 #!/bin/bash 2 ############################################ 3 # @content chapter 8,9 of Linux Command Line and Shell Scripting Bible 4 # @reader gavin 5 # @date 2014/12/14 6 ############################################ 7 CHAPTER 8 8 9 + user varriab

Scheduled Job Running Shell Script Fails With ORA-27369

Scheduled Job Running Shell Script FailsWith ORA-27369 Applies to: Oracle Server - Enterprise Edition -Version: 10.1.0.2 to 10.2.0.4 Oracle Server - Standard Edition -Version: 10.1.0.2 to 10.2.0.4 including Version:11.2.0.4 Sun Solaris SPARC (64-bit)

Why to Write Shell Script

Why to Write Shell Script ? Shell script can take input from user, file and output them on screen. Useful to create our own commands. Save lots of time. To automate some task of day today life. System Administration part can be also automated.

学习shell script

如果你的想要管理好你的主机,那么就要好好学习自动管理系统的有效工具--hell script!基本上,shell script有点像早期的批处理文件,即将很多命令整合起来一次执行,但是shell script拥有更强大的功能,它可以进行类似程序的编写,并且不需要经过编译就能够执行,非常方便我们对系统进行管理. 今天我们主要通过对一些shell script的习题来加深对脚本知识的学习. 习题1:对成绩进行判断,要求输入一个正整数,以60分,85分为界输出不同的评语. #!/bin/bash #

shell编程 Shell script 的默认变量($0, $1...)

Shell script 的默认变量($0, $1...) 我们知道指令可以带有选项与参数,例如 ls -la 可以察看包含隐藏文件的所有属性与权限.那么 shell script 能不能在脚本文件名后面带有参数呢?很有趣喔!举例来说,如果你想要重新启动系统登录文件的功能,可以这样做: [[email protected] ~]# file /etc/init.d/syslog /etc/init.d/syslog: Bourne-Again shell script text executab

執行shell script與subshell

兩種方法 喚起新shell再執行shell scripts 在目前shell執行shell scripts 喚起另一個shell來執行的scripts在scripts檔頭最前面前要加 #! /bin/sh 第一種方法是在shell script 文字檔前指出shell scripts解讀的程式在那(也就是 我們的shell)然後把文字檔的執行權限打開,照一般執行可執行檔方式執行或者叫 一個shell來解釋文字檔test.sh. $ test.sh $ /bin/sh test.sh $ ( .

linux shell script: Basic concept01 - String

basic concept01: String本文所有的测试例如无特殊说明,均based on fish shell 就从字符串说起吧,啥是字符串就不用解释了,我们来看几个简单的例子 ?> ~ set param abc ?> ~ echo "string with blank and $param surrounded with double quotation marks" string with blank and abc surrounded with double

SSH防止暴力破解 shell script

这是我的第一个Shell Script,写的乱乱糟糟,试验了一下,还是可用的,目前已经在我自己的WEB服务器上跑起来了!!~~ #!/bin/bash #这个shell script 用来防止SSH暴力破解 #Auther:Aaron Guo #Date:Jan 8 2016 #Version:1.2 # 指定该SHELL的日志文件 logfile="/var/log/blocked_ip" # 获取现在时间,用来grep /var/log/secure. (格式:mm dd HH)