zoukankan      html  css  js  c++  java
  • 解决shell错误:syntax error: unexpected end of file

    很久没有用bash的shell来编写shell复杂脚本了,今天在combo-ew的项目中,在各项测试基本上都通过之后,试图编写一个脚本,用来将tftp服务器上的驱动、应用程序和配置文件下载到combo中,并完成相应驱动卸载重新安装和配置文件的检测等。

    在terminal中运行bash -n install_combo.bsh时,总是跳出这样一个错误:install_combo.bsh: line 28: syntax error: unexpected end of file。

    一开始因为文件有130多行,为了聚焦问题产生的地方,只保留第一个if控制,其他的全都屏蔽掉。

    但是问题依然存在:

    dingq@dingq-Debug:/tftpboot$ bash -x install_combo.bsh
    ' App='combo calibrate
    ' drivers='att7053.ko led.ko key.ko relay1218.ko
    + persistence=$'combo.ini\r'
    + tmpDir=$'/tmp/combo-tmp\r'
    install_combo.bsh: line 28: syntax error: unexpected end of file

    “\r"是windows下的用的回车符,不应该在本人所用的ubuntu机器上出现。


    调试所用环境为:

    主机系统:ubuntu 11.10,编辑器vim73

    目标板系统:AT91SAM9260上安装了Linux version 2.6.24.3

    经google,发现问题可能是因为文件格式不是unix格式造成的。

    在gvim中查看当前set配置,果然发现这样一项fileformat=dos,通过:set fileformat=unix并保存文件,重新运行

    bash -x install_combo.bsh

    错误消失,问题解决了。


    想了一下,错误的根源在于,脚本文件是从附件中下载的,而附件中的文件是在windows系统中编写完成的。


    所以,写脚本还是在linux环境下用vi或者vim来写,比较省事。


  • 相关阅读:
    176. Second Highest Salary
    175. Combine Two Tables
    172. Factorial Trailing Zeroes
    171. Excel Sheet Column Number
    169. Majority Element
    168. Excel Sheet Column Title
    167. Two Sum II
    160. Intersection of Two Linked Lists
    个人博客记录
    <meta>标签
  • 原文地址:https://www.cnblogs.com/java20130726/p/3218587.html
Copyright © 2011-2022 走看看