ITPub博客

首页 > Linux操作系统 > Linux操作系统 > line 10:syntax error: unexpected end of file

line 10:syntax error: unexpected end of file

原创 Linux操作系统 作者:路途中的人2012 时间:2016-12-28 16:55:20 0 删除 编辑
在Linux运行如下脚本的时候:

点击(此处)折叠或打开

  1. #/bin/bash
  2. echo "You are logged in as `whoami`"
  3. if [ `whoami` != root ]; then
  4. echo "Must be logged on as root to run this script."
  5. fi
遇到如下错误:
line 10:syntax error: unexpected end of file

多方测试始终不见效果,最终同事陈大师找到了原因,我的脚本是从Windows上ftp到Linux上的,Linux下的文件结束符和Windows下的文件结束符不一样。在Windows上编辑的脚本,放在Linux额上运行就会有这种问题。
网上又查了以下,解决方法是使用vim打开脚本,执行命令:
set fileformat=unix
保存退出,再次执行就没有问题了。当然,也可以在Linux上重新新建一个脚本。


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29067253/viewspace-2131547/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: Collatz序列
请登录后发表评论 登录
全部评论

注册时间:2015-01-08

  • 博文量
    495
  • 访问量
    768348