使用windows系统编写shell代码,在linux执行后的报错

使用windows系统编写shell代码,在linux执行后,产生如下的错误

[[email protected] vagrant]# bash /var/www/borg/fuel/app/tasks/monitor_sync.sh
/var/www/borg/fuel/app/tasks/monitor_sync.sh: line 11: $‘\r‘: command not found
/var/www/borg/fuel/app/tasks/monitor_sync.sh: line 12: syntax error near unexpected token `$‘{\r‘‘
‘var/www/borg/fuel/app/tasks/monitor_sync.sh: line 12: `function sync(){

通过错误提示’\r’推测,这可能是window和linux的换行格式不同引起的错误

解决方法,在linux端安装dos2unix,执行如下操作

yum install dos2unix
dos2unix monitor_sync.sh

dos2unix简介

https://www.jianshu.com/p/d2e96b2ccab9

使用git 的时候碰到git将unix换行符转换为windows换行符的问题,需要使用dos2unix命令将文件转换为unix格式。

dos2unix命令用来将DOS格式的文本文件转换成UNIX格式的(DOS/MAC to UNIX text file format converter)。DOS下的文本文件是以\r\n作为断行标志的,表示成十六进制就是0D 0A。而Unix下的文本文件是以\n作为断行标志的,表示成十六进制就是0A。

而Unix格式的文本文件在Windows下用Notepad打开时会拼在一起显示。因此产生了两种格式文件相互转换的需求,对应的将UNIX格式文本文件转成成DOS格式的是unix2dos命令。

原文地址:https://www.cnblogs.com/gaoBlog/p/12244752.html

时间: 2024-08-18 11:59:18

使用windows系统编写shell代码,在linux执行后的报错的相关文章

Linux执行YUM命令报错解决方案

Loaded plugins: rhnplugin, security This system is not registered with RHN. RHN support will be disabled. Setting up Install Process No package subversion available. Nothing to do 红帽中出现"This system is not registered with RHN"这个的原因是因为红帽中没有注册RHN.

进程和程序:编写shell——《Unix/Linux编程实践教程》读书笔记(第8章)

1.Unix shell的功能 shell是一个管理进程和运行程序的程序.所有常用的shell都有3个主要功能: (1)运行程序: (2)管理输入和输出 (3)可编程 shell同时也是带有变量和流程控制的编程语言. 2.Unix的进程模型 一个程序是存储在文件中的机器指令序列,一般它是由编译器将源代码编译成二进制格式的代码.运行一个程序意味着将这些机器指令序列载入内存然后让处理器(CPU)逐条执行.在Unix术语中,一个可执行程序是一些机器指令机器数据的序列.一个进程是程序运行时的内存空间和设

windows下Python shell代码自动补全

Unix下实现如题功能用下面的代码: import rlcompleter, readline readline.parse_and_bind('tab: complete') 但readline不能在win中用,需要为windows编译好的pyreadline pip install pyreadline import rlcompleter, pyreadline a=Readline() a.parse_and_bind('tab: complete') windows下Python sh

linux下安装php报错configure: error: Cannot find MySQL header files under /usr/include/mysql.

linux下安装php报错configure: error: Cannot find MySQL header files under /usr/include/mysql. 2013-03-04 15:34wdjhz | 分类:服务器软件 | 浏览5318次 configure: error: Cannot find MySQL header files under /usr/include/mysql.Note that the MySQL client library is not bun

Linux下Oracle11G RAC报错:在安装oracle软件时报file not found一例

Linux下Oracle11G RAC报错:在安装oracle软件时报file notfound一例 1.现象 之前安装一切都比較顺利,安装oracle软件时,进度到30%时报错:file not found(/u01/app/oracle/product/11.2.0/db_1/owb/external/oc4j_applications/applications/WFMLRSVCApp.ear) 2.应对策略 1.  改变选择语言处.仅仅选择"English": 2.  又一次解压

ASP.NET MVC 复制MVC项目代码到同一个项目的时候报错The request for ‘home’ has found the following matching controll

ASP.NET MVC 复制MVC项目代码到同一个项目的时候报错The request for 'home' has found the following matching controll "/"应用程序中的服务器错误. Multiple types were found that match the controller named 'home'. This can happen if the route that services this request ('{control

linux下启动tomcat报错 Failed to get local InetAddress for VMID. This is unlikely to matter. At all. We'll add some extra randomness

INFO [localhost-startStop-1] com.mchange.v2.log.slf4j.Slf4jMLog$Slf4jMLogger$InfoLogger.log(206) | Failed to get local InetAddress for VMID. This is unlikely to matter. At all. We'll add some extra randomnessjava.net.UnknownHostException: Oracle.Linu

使用Entity Framework迁移完数据库后,每次修改代码(非模型代码)后都报错。

问题:使用Entity Framework迁移完数据库后,每次修改代码(非模型代码)后都报错: 支持“XXXDbContext”上下文的模型已在数据库创建后发生更改.请考虑使用 Code First 迁移更新数据库(http://go.microsoft.com/fwlink/?LinkId=238269). 这时如果执行 Add-Migration 生成的迁移代码是空的.于是重新Update-Database,结果却是No pending explicit migrations. 不过这时是不

Linux安装ElasticSearch启动报错的解决方法

Linux安装ElasticSearch后,ElasticSearch是不能用root用户启动的,以root用户启动会报错Refer to the log for complete error details,出现这种情况该如何解决呢?下面小编就为大家带来Linux安装ElasticSearch启动报错的解决方法,一起去看看吧 今天就出现的异常问题专门解决一下.你安装好ElasticSearch以后,在启动的时候需要注意的问题是,ElasticSearch是不能用root用户启动的(这是根据el