解决办法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. tp框架设置404页面

    无法加载模板跳向404页面 /thinkphp/library/think/Dispatcher.class.php中176行     // 加载模块的扩展配置文件             load_ ...

  2. ionic 3 热更新 Hot Code Push

    最近用ionic 3 做的app业务做的差不多了,突然想到以后app如果有更新该怎么搞?想到我们的app后期更新应该不大,,最多就是改改bug和增加下用户体验,如果只有一些小的更新,然后提交各个应用商 ...

  3. Laravel日常使用总结

    字段当做键值key 集合的keyBy()方法详情:戳这里 创建模型类和数据库迁移文件 php artisan make:model Post -m 创建控制器和基础的方法 php artisan ma ...

  4. linux 添加ssh和开启ssh服务apt管理的ubuntu

    是在ubuntu下出现的需求 现笔记记录 apt-get  update 更新源命令 apt-get  install  openssh-server 安装ssh服务 容易出现无法定位软件包.出现此问 ...

  5. Kali Linux NetHunter教程Kali NetHunter支持的设备和ROMs

    Kali Linux NetHunter教程Kali NetHunter支持的设备和ROMs NetHunter是一个基于Kali Linux为Nexus设备构建的Android渗透测试平台,其中包括 ...

  6. CSS入门介绍(一)

    css 层叠样式表(英文名:Cascading Style Sheets),主要用于美化网页 1.css的表现形式 1.1 行内样式(内嵌样式) 写在标签内的样式,写在标签的开始部分的内部,style ...

  7. (55)Wangdao.com第八天_JavaScript 字符串中使用 \u 输出Unicode字符

    JavaScript中,使用Unicode 需要 \u 进行转义,格式 "\u十六进制" console.log(\u0031); console.log(\u0041); // ...

  8. Snackbar 提醒

    类似于Toast,属于design包,不要忘记导入design package com.xiaozhuyisheng.jinjiedemos.activity; import android.supp ...

  9. OpLogMergeMessage-OutOfMemoryError-JavaHeapSpace

    direct memory size netty or oplog 5.5kw * 20 60G worker/ 26G MaxDirectMemorySize 1/2 tasks per worke ...

  10. tar:short read problem

    1. tar:short read problem description 在PC机上将需要下载到板子上的两个文件夹gdb.ncurses用tar命令打包. 命令如下:tar -cvf test5.t ...