windows下编写shell脚本运行出错问题

错误提示如下,

'ongs.sh: line 132: syntax error near unexpected token `

'ongs.sh: line 132: `list_records()


问题原因:

这种情况是因为所处理的文件换行符是dos格式的"\r\n"
可以使用cat -v 文件名 来查看换行符是否是,如果是上述的,则行结尾会是^m
list_records() ^M
{^M
echo list_records:show the songs^M
read records

}


解决方法:

需要将windows格式的"\r\n"转换成linux/unix格式的"\n",即sed -i ‘s/\r//’ 原文件


参考:http://blog.sina.com.cn/s/blog_7776b9d301014315.html

你可能感兴趣的:(windows下编写shell脚本运行出错问题)