杀虫记 #1 [shell script] - syntax error: unexpected "....&

换行大不同

Linux (LF)换行字元 => \n
window(CRLF)换行字元 =>\r\n
也就是说当使用linux环境打开window编辑的资料,会看到多一个\r,就会把它转换为^M
表面看根本看不出来,这就是危险的开始!


^M 背后灵紧跟在后

cat -v filename

#!/bin/bash^M# Basic if statement^Mif [[ "$1" -gt 100 ]]; then^M    echo Hey that\'s a large number.^M    pwd^Mfi^M^Mdate^M

解决办法 =>改运消灭它!!http://img2.58codes.com/2024/emoticon05.gif

将 fileformat 设置成 unix

set ff=unix

YES~解决啦

#!/bin/bash# Basic if statementif [[ "$1" -gt 100 ]]; then    echo Hey that\'s a large number.    pwdfidate

补充

vim

# 确认现在的file 格式:set ff#set fileformat to dos:set ff=dos#set fileformat to unix:set ff=unix#or:%s/^M//g

人生啊~~

不要留恋过往,该抛下的就抛下吧


关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章