syntax error near unexpected token `do(写的shell脚本出现格式问题)--->1.问题2.展示信息3.解决方案
1问题:Linux和windows下的回车换行符不兼容的问题
[root@node-01 script]# sh start_zk.sh
art_zk.sh: line 3: syntax error near unexpected token `do
'tart_zk.sh: line 3: `do
2.展示信息:
此处我贴出了源码;大家可以试一试:
#!/bin/sh
for host in node-01 node-02 node-03
do
ssh $host "source /etc/profile;nohup zkServer.sh > /dev/null 2>&1 &"
echo "$host zk is running"
done
3.解决方案(有两种):
看似写的完全没有问题的逻辑代码.但是只要运行就会出错.
本人是在wind本地写的shell命令,问题主要出在自己在wind上写的内容,而需要上传到linux系统上运行就会出现格式问题.
(第一种)(01).是win下的格式图片:
(02).是linux下的格式图片:
(03)设置显示上面那些黑色块:CRLF和LF
notepad++中首先设置视图->显示符号->显示所有符号,然后就看到了预料到的,所有的回车换行都是windows的CRLF
其次设置:编辑->文档格式转换->转换为UNIX格式
(04)运行成功:
(第二种)解决方案:
这里就不用上面的案例举例.这是补充方式:
(1)如果在wind上写好的没有更改格式,也可以在linux上进行查询和更改
(2)例如root目录下有一个 itcast_gdm_user_basic.sh文件
(3)vim itcast_gdm_user_basic.sh
(4)进去以后直接输入 :set fileformat 回车
如果显示是fileformat=dos 就说明是wind格式
如果显示是fileformat=unix 就说明是linux格式
(5)更改格式: 直接输入 :set fileformat=unix 回车就更该完成
(6)再次确认是否成功,重新执行(4)
syntax error near unexpected token `do(写的shell脚本出现格式问题)--->1.问题2.展示信息3.解决方案的更多相关文章
- 写shell,运行出错:syntax error near unexpected token `$’do\r”
cygwin下面写shell,运行出错:syntax error near unexpected token `$’do\r” 写shell,运行出错:syntax error near unexpe ...
- linux后台执行./run.py提示python syntax error near unexpected token `('
python脚本中的#!/usr/bin/python 估计有不少人注意过一些python脚本开头有这么行东东: #!/usr/bin/python 它是用来干嘛的?貌似没有它对脚本功能也没啥 ...
- 关于报错“syntax error near unexpected token `”和回车换行
本来是很简单一个事情,转过来是因为打字机这事比较有趣…… http://blog.csdn.net/xyp84/archive/2009/08/11/4435899.aspx 摘要一下: 回车 换行 ...
- shell编程报错:“syntax error near unexpected token `”
今天写了个shell脚本,在自己机器上运行正常,给同事,运行报错syntax error near unexpected token `,左看右看shell脚本没有问题,没有办法google搜索,发现 ...
- $'\r': command not found 或者 syntax error: unexpected end of file 或者 syntax error near unexpected token `$'\r''
执行shell脚本如果报如下错误: syntax error near unexpected token `$'\r'' syntax error: unexpected end of file $' ...
- Linix登录报"/etc/profile: line 11: syntax error near unexpected token `$'{\r''"
同事反馈他在一测试服务器(CentOS Linux release 7.2.1511)上修改了/etc/profile文件后,使用source命令不能生效,让我帮忙看看,结果使用SecureCRT一登 ...
- Linux中syntax error near unexpected token 错误提示解决方法
Linux中syntax error near unexpected token ... 错误提示有一般有两种原因: 1)window和Linux下换行符不一致导致 window下的换行和Linux下 ...
- syntax error near unexpected token `then'问题的解决
#!/bin/bash #if program test echo 'a:' read a if [ "$a" = "English" ];then ...
- 使用cygwin出现syntax error near unexpected token'$'do\r
直接从csdn复制粘贴的.sh代码,放到cygwin下运行sh的时候出错syntax error near unexpected token'$'do\r 解决方法: 1.下载notepad++ 2. ...
随机推荐
- bugku web 矛盾
$num=$_GET['num'];if(!is_numeric($num)){echo $num;if($num==1)echo 'flag{**********}';} 首先要判断get得到的数据 ...
- [数据库] windows server 2003下mysql出现10048错误的解决办法 Can't connect to MySQL server on '127.0.0.1' (10048)(抄)
网站访问量大了的时候mysql连接数自然就多了,当超出mysql最大连接数的时候就会出现错误,当出现too many字样的错误的时候一般是因为连接数的问题,只需要修改最大连接数max_conectio ...
- java回调函数,看完就懂
java回调函数在网上了看了些例子,比较绕,不够清晰,自己写的一个例子比较通俗,java回调其实很简单. 举个例子我是类B,我有个方法叫b(),现在我要调用类A中的方法a(),写个代码就是: publ ...
- Linux-ftp虚拟用户配置
云服务器ESC 部署vsftpd 虚拟用户 说明:云服务器部署和本地服务器部署一样,都需要开通指定的相应端口,只不过云服务器需要在安全组规则中打开相应的端口允许通过. 环境说明: 对应的用户对应不同的 ...
- ElasticSearch常用操作命令
查看系统信息: curl 'http://username:password@192.168.0.40:9200/' curl 'http://username:password@127.0.0.1: ...
- SpringMVC 文件上传下载
目录 文件上传 MultipartFile对象 文件下载 上传下载示例 pom.xml增加 创建uploadForm.jsp 创建uploadForm2.jsp 创建userInfo.jsp spri ...
- 你需要Mobx还是Redux?
在过去一年,越来越多的项目继续或者开始使用React和Redux开发,这是目前前端业内很普遍的一种前端项目解决方案,但是随着开发项目越来越多,越来越多样化时,个人又有了不同的感受和想法.是不是因为已经 ...
- win 10 dpi 缩放
win 10 dpi dwm 效果,影响最大的函数有 参考资料:https://blog.csdn.net/chenlycly/article/details/53142098 GetSystemMe ...
- 阿里百川SDK初始化失败 错误码是203
由idea换到Androidstudio 了,结果报这个错,之前好好的啊!!! 设置问题:
- thrift使用
一.什么是thrift Thrift是一种接口描述语言和二进制通讯协议,它被用来定义和创建跨语言的服务.它被当作一个远程过程调用(RPC)框架来使用,是由FaceBook为“大规模跨语言服务开发”而开 ...