Linux shell line 4: There is a syntax error near the unexpected symbol `$'\r''

the reason

Execute shell script error:

Line 4: There is a syntax error near the unexpected symbol `$'\r''

Copying files from window to linux has format problems that cannot be resolved

Solution

Install yum install -y dos2unix

[root@zjj101 soft]# yum install -y dos2unix
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.bfsu.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 dos2unix.x86_64.0.6.0.3-7.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

======================================================================================================================
 Package                     架构                      版本                             源                       大小
======================================================================================================================
正在安装:
 dos2unix                    x86_64                    6.0.3-7.el7                      base                     74 k

事务概要
======================================================================================================================
安装  1 软件包

总下载量:74 k
安装大小:190 k
Downloading packages:
dos2unix-6.0.3-7.el7.x86_64.rpm                                                                |  74 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : dos2unix-6.0.3-7.el7.x86_64                                                                       1/1 
  验证中      : dos2unix-6.0.3-7.el7.x86_64                                                                       1/1 

已安装:
  dos2unix.x86_64 0:6.0.3-7.el7                                                                                       

完毕!

Transcoding the file
What file I transcode, just dos2unix file name, for example, if I transcode xcall, just dos2unix xcall is fine

[root@zjj101 soft]# ls
data  demo  docker  hadoop-2.7.2  hive-1.2.1  movie_info.txt  myconf  sortby-result  tmp  xcall  xsync
[root@zjj101 soft]# dos2unix xcall 
dos2unix: converting file xcall to Unix format ...

note

If you copy new things in this file from windows, if you run the shell script and prompt an unexpected symbol `$'\r'' near the syntax error, then execute the above command again, which is dos2unix xxxxxx Command to transcode the xxxxxx file again

Guess you like

Origin blog.csdn.net/qq_41489540/article/details/109094955