Línea 4 del shell de Linux: hay un error de sintaxis cerca del símbolo inesperado `` $ '\ r' '

la razón

Error al ejecutar el script de shell:

Línea 4: hay un error de sintaxis cerca del símbolo inesperado `` $ '\ r' '

Copiar archivos de Windows a Linux tiene problemas de formato que no se pueden resolver

Solución

Instalar 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                                                                                       

完毕!

Transcodificación del archivo
Qué archivo transcodifico, solo el nombre del archivo dos2unix, por ejemplo, si transcodifico xcall, dos2unix xcall servirá.

[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 ...

Nota

Si copia cosas nuevas en este archivo desde Windows, si ejecuta el script de shell y solicita un símbolo inesperado `` $ '\ r' 'cerca del error de sintaxis, luego ejecute el comando anterior nuevamente, que es dos2unix xxxxxx Comando para transcodificar el archivo xxxxxx nuevamente

Supongo que te gusta

Origin blog.csdn.net/qq_41489540/article/details/109094955
Recomendado
Clasificación