2014-06-19 BaoXinjian

1. Issue

调用如下Shell脚本时出现错误syntax error near unexpected token `fi'

Error_Unix Shell_syntax error near unexpected token `fi'

 

2. Cause

Unix 和 Window存放文件时其编码方式是不一致的,导致Window写好的文件放到Unix中,会有部分乱码出现,主要是换行阶段

Error_Unix Shell_syntax error near unexpected token `fi'

 

3. Solution

Step1. 调用命令> vi - b bxjsqplus2.sh

Error_Unix Shell_syntax error near unexpected token `fi'

Step2. 执行修改命令> :%s/^M//g

Step3. 保存退出> :wq

注意:

  • 因为MS-DOS及Windows是回车+换行来表示换行,因此在Linux下用Vim查看在Windows下用VC写的代码,行尾后的“^M”符号,表示的是符。
  • 上述命令行中的“^M”符,不是“^”再加上“M”,而是由“Ctrl+v”、“Ctrl+M”键生成的。
  • 这样替换掉以后,保存就可以执行了。当然还有其他的替换方式比如: 通过使用带window编码Unix编码转换功能的编辑器

 

Thanks and Regards

相关文章:

  • 2021-08-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-24
  • 2021-07-31
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-07-09
  • 2021-08-30
  • 2021-12-16
  • 2022-12-23
  • 2022-12-23
  • 2021-04-13
相关资源
相似解决方案