解决办法1:

vi test.sh
:set fileformat=unix
:wq

解决办法2:

yum install dos2unix
dos2unix my.sh

原因剖析:

DOS下文件和Linux下文件格式差异问题导致的。【在windows里,换行用的两个符号,回车\r,换行符号\n,在linux下只需一个符号\n就可以了.】

shell脚本报错:syntax error: unexpected end of file的更多相关文章

  1. 【shell】真正解决syntax error:unexpected end of file?

    今天写了个较长的shell脚本,结构嵌套比较多,最后运行时,出现了syntax error: unexpected end of file的错误. 这个之前碰到过,经常在win系统转移脚本文件到uni ...

  2. php Yii2使用registerJs或registerCss报错syntax error, unexpected end of file

    解决方法: 注册时$js=<<<JS .....JS;//结尾处JS;应单独成行并且没有空格  JS;//这样就会报错,多了空格JS;//这样就不会

  3. shell 报错:syntax error: unexpected end of file

    有时执行脚本时会报错: [root@host1 shell]# sh -x test.sh + $'\r' : command not found test.: syntax error: unexp ...

  4. 报错解决——linux下执行sh出现异常"syntax error: unexpected end of file"

    有时我们在linux下执行一个sh文件,会报错“SYNTAX ERROR:UNEXPECTED END OF FILE”,这个现象主要是工作的系统环境改变造成的. 若最初脚本中是在windows下,使 ...

  5. Linux下docker报错syntax error:unexpected protocol at end of statement

    ---恢复内容开始--- [Linux]Shell脚本“syntax error: unexpected end of file”原因及处理 :::https://blog.csdn.net/u013 ...

  6. 执行shell脚本报错:syntax error near unexpected token `或syntax error: unexpected end of file

    引起此问题最可能的原因是: 在windows下编写的文件上传到linux执行. 我是在notepad++上编写的代码,之后上传到linux执行,报此错误.仔细检查,语法方面没有错误.上网查了一下,发现 ...

  7. 解决执行脚本报syntax error: unexpected end of file或syntax error near unexpected token `fi'错误的问题

    参考:https://blog.csdn.net/u012453843/article/details/69803244 解决执行脚本报syntax error: unexpected end of ...

  8. SHELL syntax error:unexpected end of file 提示错误

    SHELL syntax error:unexpected end of file 提示错误 if [ -n "$1" ] then " else " fi e ...

  9. shell脚本报错:"[: =: unary operator expected"

    shell脚本报错:"[: =: unary operator expected" 在匹配字符串相等时,我用了类似这样的语句: if [ $STATUS == "OK&q ...

  10. shell:syntax error:unexpected end of file/Starting proxy www-balancer: cannot bind socket--转载

    src:http://www.2cto.com/os/201308/238962.html   执行某bash脚本是发生: syntax error: unexpected end of file 主 ...

随机推荐

  1. java 查找类的所有子类

    package _02; import java.io.File; import java.net.URL; public class MainTest_FindAllSubClass { publi ...

  2. zt 正则

    http://deerchao.net/tutorials/regex/regex.htm     正则表达式30分钟入门教程 版本:v2.3.5 (2017-6-12) 作者:deerchao 转载 ...

  3. Web微信模拟

    一.概要 目的:实现一个具有web微信类似功能的项目 框架:Django 模块:render.HttpResponse.BeautifulSoup.re.time.requests.json.rand ...

  4. C语言fread/fwrite填坑记

    坑的描述 用fwrite把数据写入文件,再用fread读取,发现后半部分的数据可能是错的. 原因:原本要写入文件的数据中,有0x0A,如果用的是文本模式打开的文件流,在windows下0x0A会被转换 ...

  5. 一条很用的MSSQL语句

    select *,ActionName= stuff((select ',' + ActionName from Sys_Action_Table where ModuleId = Sys_Modul ...

  6. 使用 NPOI 导出 Excel 文件

    [NPOI简介] NPOI 是 POI 项目的 .NET 版本.POI是一个开源的Java读写Excel.WORD等微软OLE2组件文档的项目. 使用 NPOI 你就可以在没有安装 Office 或者 ...

  7. day15.Python内置函数

    作用域相关 locals() -- 获取执行本方法所在命名空间的局部变量的字典 globals() --  获取全局变量的字典 print(locals()) print(globals()) {'_ ...

  8. C语言面对对象设计模式汇编

    面向对象发展到今天,已经出现了许许多多优秀的实践.方法和技术.很多的技术都能够有效的提高软件质量.IBM上的<面向对象软件开发和过程>系列文章对面对对象设计从如下层面进行了详细的介绍:代码 ...

  9. ajax 三种数据格式

    1.JSON(格式要正确,可以引jar包操作) servlet代码 package com.hsp.action; import java.io.IOException; import java.io ...

  10. Go九九乘法表

    package main import "fmt" func main(){ ; i < ; i ++ { k ++ ; j ++ { { fmt.Printf(" ...