#bash
if [ "$1" = "cm" ]
then
echo "ok"
fi
exit 0
linux-6lod:/home/yq # ./start.sh "cm"
./start.sh: line 7: syntax error: unexpected end of file
linux-6lod:/home/yq # ./start.sh cm
./start.sh: line 7: syntax error: unexpected end of file
linux-6lod:/home/yq #
------解决方案--------------------
你的脚步里有汉字字符 或者windows下的字符
/bin/bash^M
从这句就能看出来
把下面的代码直接复制到你的linux里去
- CSS code
#!/bin/bash if [ "$1" = "cm" ] then echo "ok" fi exit 0
------解决方案--------------------
你这样试试dos2unix start.sh
然后再执行./start.sh cm
------解决方案--------------------
------解决方案--------------------
dos/windows 下的回车、换行占2个字节: 0d 0a
unix/linux 下的回车占1个字节:0d
windows下写的文本文件直接拷贝到linux下,打开就会出现问题:
/bin/bash^M ——最后多一个 ^M
楼上的 dos2unix 方法可以解决。
另外,也有可能你的系统上用的不是 bash,需要换个shell用用
比如:
#!/bin/sh
#!/bin/ksh
等