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.解决方案的更多相关文章

  1. 写shell,运行出错:syntax error near unexpected token `$’do\r”

    cygwin下面写shell,运行出错:syntax error near unexpected token `$’do\r” 写shell,运行出错:syntax error near unexpe ...

  2. linux后台执行./run.py提示python syntax error near unexpected token `('

    python脚本中的#!/usr/bin/python     估计有不少人注意过一些python脚本开头有这么行东东: #!/usr/bin/python 它是用来干嘛的?貌似没有它对脚本功能也没啥 ...

  3. 关于报错“syntax error near unexpected token `”和回车换行

    本来是很简单一个事情,转过来是因为打字机这事比较有趣…… http://blog.csdn.net/xyp84/archive/2009/08/11/4435899.aspx 摘要一下: 回车 换行 ...

  4. shell编程报错:“syntax error near unexpected token `”

    今天写了个shell脚本,在自己机器上运行正常,给同事,运行报错syntax error near unexpected token `,左看右看shell脚本没有问题,没有办法google搜索,发现 ...

  5. $'\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 $' ...

  6. Linix登录报"/etc/profile: line 11: syntax error near unexpected token `$'{\r''"

    同事反馈他在一测试服务器(CentOS Linux release 7.2.1511)上修改了/etc/profile文件后,使用source命令不能生效,让我帮忙看看,结果使用SecureCRT一登 ...

  7. Linux中syntax error near unexpected token 错误提示解决方法

    Linux中syntax error near unexpected token ... 错误提示有一般有两种原因: 1)window和Linux下换行符不一致导致 window下的换行和Linux下 ...

  8. syntax error near unexpected token `then'问题的解决

    #!/bin/bash #if program test echo 'a:' read a if  [  "$a"  =  "English"  ];then ...

  9. 使用cygwin出现syntax error near unexpected token'$'do\r

    直接从csdn复制粘贴的.sh代码,放到cygwin下运行sh的时候出错syntax error near unexpected token'$'do\r 解决方法: 1.下载notepad++ 2. ...

随机推荐

  1. 使用nio遍历文件夹

    1.递归方式: private static void print(File f){ if(f!=null){ if(f.isDirectory()){ File[] fileArray=f.list ...

  2. 龙光集团地产跃居“中国房地产500强TOP28”

    3月20日,由中国房地产业协会.上海易居房地产研究院中国房地产测评中心联合主办的2019中国房地产500强测评成果发布会在北京成功举办.本次测评成果显示,龙光集团地产凭借综合实力,不仅成功跻身“中国房 ...

  3. Spring Boot + Netty 中 @Autowired, @Value 为空解决

    问题描述 使用 Spring Boot + Netty 新建项目时 Handler 中的 @Autowired, @Value 注解的始终为空值 解决方法 @Component // 1. 添加 @C ...

  4. <TCP/IP原理> (一)

    1.协议和标准 2.标准化组织 3.Internet标准:RFC 4.Internet的管理机构 一.协议和标准 1.协议(Protocol) 一组控制数据通信的规则 三要素:语法(syntax).语 ...

  5. [Storage]RPM series linux rescan disk / RPM系Linux重新扫描硬盘

    echo "- - -" > /sys/class/scsi_host/host0/scan echo "- - -" > /sys/class/s ...

  6. Linux安装NodeJS

    Linux中安装nodejs 去官网下载和自己系统匹配的文件: 英文网址:https://nodejs.org/en/download/ 中文网址:http://nodejs.cn/download/ ...

  7. bzoj1997 Planar

    题目链接 思路 首先以那个环为框架,把所有的边连出来.如果有两条边相交,那么就把其中一条放到环外面去. 如图: \((1,3)\)与\((2,5)相交,\)(1,4)\(与\)(2,5)相交.所以我们 ...

  8. nowcoder300J Mex

    题目链接 题意 给出一个长度为\(n(n \le 10^5)\)序列,求其每个子序列之和所组成的集合的\(mex\) 思路 这么水的题都没想出来,感觉自己脑子瓦特了. 假设前\(i\)位可以组成区间\ ...

  9. MVN TEST指定运行脚本

    clean:表示将你上一次编译生成的一些文件删除 test:表示只执行测试代码 >mvn clean test -Dtest=[ClassName] 运行测试类中指定的方法:这个需要maven- ...

  10. JS学习笔记Day20

    一. 1.服务器和客户端 客户端 程序: 通过浏览器直接运行 服务器 程序: 通过安装某种服务器软件   程序才可以运行              apache   php文件             ...