解决办法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. Vue 增删改查 demo

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  2. CodeForces 958F3 Lightsabers (hard) 启发式合并/分治 多项式 FFT

    原文链接http://www.cnblogs.com/zhouzhendong/p/8835443.html 题目传送门 - CodeForces 958F3 题意 有$n$个球,球有$m$种颜色,分 ...

  3. Servlet(六):Cookie

    Cookie 学习:问题: HTTP 协议是没有记忆功能的,一次请求结束后,相关数据会被销毁.如果第二次的请求需要使用相同的请求数据怎么办呢?难道是让用户再次请求书写吗?解决: 使用 Cookie 技 ...

  4. Servlet(五):请求转发和重定向

    请求转发: 问题: 服务器在接收到浏览器的请求后,仅仅使用一个 Servlet进行请求处理,会造成不同的Servlet逻辑代码 冗余,Servlet的职责不明确. 解决: 使用请求转发. 特点: 一次 ...

  5. .Net Core WebAPI 搭建

    .Net Core WebAPI 搭建 1.创建项目 使用开发工具为 Visual Studio 2017 2.创建 Controller 实体类 public class Book { public ...

  6. C++ log4cplus 类库的封装

    对 log4cplus 库的封装,修改自网路 LogUtils.h /* * LogUtils.h * * Created on: 2018年8月9日 * Author: oftenlin */ #i ...

  7. python MRO:C3算法

    http://www.codeweblog.com/python-mro-c3%E7%AE%97%E6%B3%95/ 在 python 2.2 之后,python 实现了一个新的MRO算法:C3算法, ...

  8. PermissionDispatcher 运行时权限框架

    第一步在app的build.gradle文件中添加: dependencies { // PermissionDispatcher 框架的使用 implementation 'com.github.h ...

  9. PAT甲级1022 Digital Library

    题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805480801550336 题意: 每一本书有一个id, 书名,作 ...

  10. VBA - ONE

    1. Grouping our code (1)  Modules