点击(此处)折叠或打开
- #/bin/bash
- echo "You are logged in as `whoami`"
- if [ `whoami` != root ]; then
- echo "Must be logged on as root to run this script."
- fi
line 10:syntax error: unexpected end of file
多方测试始终不见效果,最终同事陈大师找到了原因,我的脚本是从Windows上ftp到Linux上的,Linux下的文件结束符和Windows下的文件结束符不一样。在Windows上编辑的脚本,放在Linux额上运行就会有这种问题。
网上又查了以下,解决方法是使用vim打开脚本,执行命令:
set fileformat=unix
保存退出,再次执行就没有问题了。当然,也可以在Linux上重新新建一个脚本。