关于shell文件中出现syntax error: unexpected end of file

来源:互联网 发布:阿里云服务器安装镜像 编辑:程序博客网 时间:2024/06/05 11:21
有两种情况会出现这种错误
1.你在window下编辑的文件直接拷贝到linux下会报这种错(如果你确定你的文件没有在window下编辑过,可直接看第二种情况)
解决方法:利用dos2unix将文件转换为unix(本人用os,命令brew install dos2unix, centos下用yum,ubuntu用apt-get)
安装完后运行:  dos2unix -n profile profile 就解决了


2.如果第一种情况转换后还有问题,说明你程序内部出现了问题
一般分为两种:if语句没有fi结尾,for循环没有done结尾。
正确的用法如下
if [];
then
 echo "a"
else
 echo "b"
fi


for i in *.sh; do
  echo "c"
done
1 0