在Linux系统配置Java环境变量之后执行 source /etc/profile指令报:-bash: /etc/profile: line 11: syntax error near unexpected token `$'{\r''如下图:

错误提示信息已经反馈/etc/profile里面有一些异常,初步检查/et/profile文件后,没有发现异常,很是奇怪,后面我使用cat -v /etc/profile检查,发现里面大量的Windows下的换行符。如下截图所示

得知是Linux和windows下的回车换行符不兼容的问题。

所以,剩下的就是去将windows下面的CR LF,转换为Linux下面的LF,即可。

此处,不需要再麻烦地去用其他dos2unix等工具了,notepad++就可以帮忙搞定:

编辑->档案格式转换->转换为UNIX格式:

即可将所有的 CR LF,转换为LF:

所以,越加发现notepad++的强大之处了。

然后再运行此shell脚本,即可正常运行了。

【总结】

linux/cygwin下面的shell脚本出现错误:

syntax error near unexpected token `$’do\r”

是由于该脚本文件是在windows环境下创建编辑的,其默认是将所有的回车变成:

CR加上 LF,而Linux/Unix中的回车只是LF,所以导致解释器不认,出现此错误。

解决办法就是,将所有的CRLF转换为LF即可。

转换的方法有多种,比如用dos2unix,或用此处的notepad++帮我们转换,都可以。

-bash: /etc/profile: line 11: syntax error near unexpected token `$'{\r''报错问题解决的更多相关文章

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

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

  2. 可执行程序无法在Linux上运行,显示line 1: syntax error: word unexpected (expecting ") .

    [问题]用arm-linux-gcc编译出来的可执行文件clkCtl,下载到板子上,在Linux下不能运行:./clkCtl: line 1: syntax error: word unexpecte ...

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

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

  4. libtool: syntax error near unexpected token `]*

    ../libtool: line 543: syntax error near unexpected token `]*' ../libtool: line 543: `      *[\[\~\#\ ...

  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. Linux 中出现的-bash: syntax error near unexpected token `

    版权声明:本文为博主原创文章,未经博主允许不得转载. 在Linux 5中导入数据时,出现下面的错误. -bash: syntax error near unexpected token `(' 检查了 ...

  7. -bash:syntax error near unexpected token '('

    在Xshell5中编写int main(int argc,char** argv)时, 出现-bash:syntax error near unexpected token '('  : 可是我是按照 ...

  8. line: 1: Syntax error: word unexpected (expecting ")")

    开发板上运行可执行程序报出错误: line1: 1: Syntax error: word unexpected (expecting ")") 解决思路: 1.编译器的问题 用a ...

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

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

随机推荐

  1. 详细解说Windows 8.1与Windows 8的区别(Win8.1与Win8区别)

    详细解说Windows 8.1与Windows 8的区别(Win8.1与Win8区别) 本文转自“吾乐吧软件站”,原文链接:http://www.wuleba.com/?p=23082 最近,吾乐吧软 ...

  2. sshj 示例

    sshj 示例 开发常常需要去服务器做一些操作,比如配置一下,或者取服务器的配置什么的,需要写点工具方便开发. 下面是一个使用sshj 模拟ssh的过程. package sshStuff; impo ...

  3. cached_property的使用

    cached_property修饰过的函数,变成是对象的属性,该对象第一次引用该属性时,会调用函数,对象第二次引用该属性时就直接从词典中取了,这也说明引用属性是经过__getattritue__. c ...

  4. visual studio split edit window 编辑器窗口分屏

    OR

  5. Tomcat 启动时 SecureRandom 非常慢解决办法,亲测有效

    1.找到jre—>lib—>security 2.找到      securerandom.source=file:/dev/random 替换成:securerandom.source= ...

  6. Hadoop Mapreduce运行流程

    Mapreduce的运算过程为两个阶段: 第一个阶段的map task相互独立,完全并行: 第二个阶段的reduce task也是相互独立,但依赖于上一阶段所有map task并发实例的输出: 这些t ...

  7. Innodb引擎中Count(*)

    select count(*)是MySQL中用于统计记录行数最常用的方法,count方法可以返回表内精确的行数. 在某些索引下是好事,但是如果表中有主键,count(*)的速度就会很慢,特别在千万记录 ...

  8. python字符串 列表 元组 字典相关操作函数总结

    1.字符串操作函数 find 在字符串中查找子串,找到首次出现的位置,返回下标,找不到返回-1 rfind 从右边查找 join 连接字符串数组 replace 用指定内容替换指定内容,可以指定次数 ...

  9. go调查内存泄漏

    curl x.x.x.x/debug/pprof/heap > base.heap 过段时间 curl x.x.x.x/debug/pprof/heap > current.heap go ...

  10. 吴裕雄 python 机器学习——Lasso回归

    import numpy as np import matplotlib.pyplot as plt from sklearn import datasets, linear_model from s ...