shell 脚本报错^M: syntax error near unexpected token

配置seata的nacos-config.sh出现:syntax error near unexpected token ‘newline‘的最全解决措施 Shell脚本来在Linux试用以及seata配置中nacos-config.sh执行出现的syntax error near unexpected token ‘newline'完美解决的全套方法,发现执行时就报错:syntax error near unexpected token完美解决 阅读详情

  以前写shell脚本运行的好好的,今天再运行突然出现了错误:

syntax error near unexpected token `

  网上搜了下正好有人遇到过这个问题,并且给出了解决方式,于是乎就转过来了:

  用命令vi -b 打开你的SHELL脚本文件,你会。发现每行脚本最后多了个^M。

  那么接下来就要搞清楚这个^M是什么东东?

  long long ago….. 老式的电传打字机使用两个字符来另起新行。一个字符把滑动架移回首位 (称为回车,<CR>,ASCII码为0D),另一个字符把纸上移一行 (称为换行, <LF>,ASCII码为0A)。当计算机问世以后,存储器曾经非常昂贵。有些人就认定没必要用两个字符来表示行尾。UNIX 开发者决定他们可以用一个字符来表示行尾,Linux沿袭Unix,也是<LF>。Apple 开发者规定了用<CR>。开发 MS-DOS以及Windows 的那些家伙则决定沿用老式的。

  因为MS-DOS及Windows是回车+换行来表示换行,因此在Linux下用Vim查看在Windows下用VC写的代码,行尾后的“^M”符号,表示的是符。

  在Vim中解决这个问题,很简单,在Vim中利用替换功能就可以将“^M”都干掉,键入如下替换命令行:

  • 1)vi -b setup.sh

  • 2)在命令编辑行<就是: 按ESC键 然后shift+:冒号>输入: %s/^M//g

注意:上述命令行中的“^M”符,不是“^”再加上“M”,而是由“Ctrl+v”、“Ctrl+M”键生成的。

  这样替换掉以后,保存就可以执行了。当然还有其他的替换方式比如:

  • a. 一些 linux 版本有 dos2unix 程序,可以用来祛除^M。(同样的也有 unix2dos )

  • b. cat filename1 | tr -d "/r" > newfile 去掉^M生成一个新文件,还有sed命令等,凡是可以替换的命令都是可以用来新生成一个文件的。

  按照上面所说的,删除”^M” shell脚本就运行正常,后来问同事,原来他windows记事本中修改了程序路径,导致每一行多出了^M。

操作系统 | 知识梳理 | 复习(上) 操作系统复习 阅读详情

相关推荐

Linux SMP系统多核启动机制详解

对称多处理(SMP)是现代操作系统支持多核并行计算的基础架构。其核心原理是通过引导处理器(BSP)初始化系统环境后,通过处理器间中断(IPI)机制唤醒应用处理器(AP)。在x86架构中,AP启动时处于实模式,需要特殊的trampoline代码完成保护模式切换和分页设置。这种设计既保证了系统初始化的正确性,又实现了多核并行处理的性能优势。理解SMP启动流程对优化系统启动速度和调试多核问题至关重要,特别是在云计算和嵌入式系统中,高效的SMP初始化能显著提升系统响应能力。本文以Linux内核为例,深入解析了从BS

weixin_35006125的博客 289

shell脚本中出现^M

在Windows中编辑的shell脚本,传到linux系统中,在末尾发现出现了很多^M字符 1.问题分析 在windows下使用notepad++写的脚本上传到Linux下,在使用vim编辑的时候我们发现在行末出现了^M。 2.^M的来历 ^M字符的来历和作用:在DOS/Windows里,文本文件的换行符为\r\n,而在nix系统里则为\n,所以DOS/Windows里编辑过的文本文件到...

dbkpcg7449的博客 809

Modscan32连接上了却没数据?一文拆解所有报错(从“Device NOT CONNECTED”到“Checksum Error”)

本文深入解析Modscan32连接异常问题,从状态栏报错到数据异常,提供系统化的诊断思路和解决方案。涵盖物理层问题、配置参数错位、端口占用冲突等常见故障,帮助工程师快速定位和解决Modbus通信中的各类错误。

weixin_30384217的博客 397

解决 Linux shell 脚本文件出现 ^M 字符的问题(亲自验证)

(1)在Windows编辑Shell脚本,会在行末尾显示^M。这是不同的操作系统对换行处理的结果。(3)通过cat -A net.sh,发现脚本文件多了很多^M 字符。sed -i "s/\r//" 文件名。(1)在Windows 的编辑器编写Shell脚本。(2)拷贝到Linux 去执行,执行失败。

yangbingnew的专栏 4307

在Window上安装和配置VTK9.x,并在QT项目中调试VTK是否可用

VTK+MSVC+Qt Creator + CMake配置

qq_42279379的博客 1000

RK3576平台部署NanoTrack:边缘AI视觉跟踪实战指南

边缘AI部署是将深度学习模型在资源受限的嵌入式设备上高效运行的关键技术,其核心在于模型压缩、硬件适配与软件栈优化。通过INT8量化、算子融合与内存优化等原理,能显著降低模型计算量与内存占用,从而在嵌入式NPU上实现实时推理。这项技术的价值在于为安防监控、无人机视觉、工业检测等场景提供低功耗、高响应的智能感知能力。以瑞芯微RK3576平台部署轻量级视觉跟踪模型NanoTrack为例,其过程涉及模型结构分析、RKNN工具链转换、C++推理程序开发及多线程性能优化,完整展现了从算法到产品的工程化路径,为开发者提供

weixin_31887307的博客 426

linux脚本在每行后面自动添加,shell 脚本每行后面多了一个^M的原因和解决方法...

用命令vi -b 打开你的SHELL脚本文件,你会。发现每行脚本最后多了个^M。那么接下来就要搞清楚这个^M是什么东东?long long ago….. 老式的电传打字机使用两个字符来另起新行。一个字符把滑动架移回首位 (称为回车,,ASCII 码为0D),另一个字符把纸上移一行 (称为换行, ,ASCII码为0A)。当计算机问世以后,存储器曾经非常昂贵。有些人就认定没必要用两个字符来表示行尾。U...

weixin_32520565的博客 1480

用Django框架+爬虫技术实现自动获取可画(Canva)团队会员资格的方法

可画(canva)是一个非常流行的在线平面设计平台,因为它无需专业训练和技能就可以利用其丰富的资源设计出美观、酷炫的作品,因而它受到了极其广泛的设计专业和非专业人群的喜爱本文介绍了一种方法,它采用Django网络框架与爬虫技术相结合,实时监控定时更新可画团队版免费邀请链接的网站页面,一旦链接有更新动作,第一时间获取相关信息,并直接加载这个有效的邀请链接,自动进入可画网站获得团队版使用资格。

hhyyqq的博客 2207

Shell脚本中^M的问题和解决方案

shell脚本中 ^M问题 在开发过程中,有时候不小心将Windows本地创建的shell脚本(以 .sh 结尾的脚本),传到linux系统中,通过 vi或者view命令查看文件时,发现在末尾发现出现了很多^M字符。 ^M 是什么? 这个字符就是换行符。是由于跨平台解析的原因。 因为window和Linux下对行尾的换行的定义不同 Windows: \r\n Linux/Unix: \n Mac: \r 例子 出现的原因: 在DOS/Windows里,文本文件的换行符为\r\n,而在nix系统里则为

csdnjsj的博客 7876

YOLO11改进|卷积篇|引入多样化分支块DBB

YOLO11中添加多样化分支块DBB

A1983Z的博客 1444

n8n AI高效工作流自动化 部署使用教程

摘要: n8n是一款开源可视化工作流自动化工具,结合AI能力可高效解决重复性任务。文章详细介绍了从Docker部署到实战应用的完整流程:1)通过Docker Compose自托管n8n,确保数据可控;2)以AI客服日报机器人为例,演示如何串联工单系统、ChatGPT和邮件通知,实现定时自动化;3)进阶搭建交互式AI助手,利用ToolsAgent节点调用业务API;4)整合向量数据库构建RAG知识库问答。关键建议包括:拆分复杂工作流、严格管理凭据、区分开发与生产环境,并建议从高频刚性需求(如日报生成)切入,逐

专注AI大模型,软件混淆,授权 266

shell 脚本^M

shell ^M

weixin_44487073的博客 437

创建 Qt Quick 项目

来看看如何使用 Qt Creator 创建 Qt Quick 项目!

青春不老,奋斗不止! 1万+

linux shell脚本无法执行,报错syntax error near unexpected token `$'\r''解决方法

最近一直由于项目上的要求在编写各种自动化安装的脚本,正好有一个需求是在之前的项目上编写过的,目前只需要拿来修改下即可。 之前的shell脚本是在服务器上编写的,后来又已复制的方式存在在了电脑上,以txt文件的形式存放的。于是复制到了编辑工具中,进行了相应项的修改。修改完毕后,拿到服务器上测试,结果执行sh XXX.sh后就一直提示 很是奇怪????脚本检查了没有错误的,为什么会有这个提示呢。 使...

skyfans的博客 4万+

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

解决shell脚本“syntax error near unexpected token `fi'”的问题。

先列出我的shell脚本。 我是在windows编辑器里面编辑好之后再上传到linux进行执行的。 #!/bin/bash Monitor() { pgrep -x mysqld &> /dev/null if [ $? -ne 0 ]; then echo "At time: `date` :MySQLis stop .">> /opt/service...

D.K专栏 5万+

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

运行shell脚本报错:“syntax error near unexpected token 的解决方法`”

运行shell脚本报错:“syntax error near unexpected token 的解决方法`” 今天写了个Cshell脚本,运行报错syntax error near unexpected token `,脚本语法没有问题,最后发现了问题 用命令vi -b 打开你的SHELL脚本文件,你会。发现每行脚本最后多了个^M。 老式的电传打字机使用两个字符来另起新行。一个字符把滑动架...

Alfred的博客 2万+

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Shell脚本执行报错:“syntax error near unexpected token ”

Shell脚本执行报错:“syntax error near unexpected token ”第一步:执行 vi -b test.sh第二步: 替换:shift+:冒号&gt;输入:%s/^M//g 今天写了一个shell脚本(在windows上 写的,移到linux上),然后在执行的时候,一直报错如下: 开始我以为是脚本语法问题,怎么改都执行不了,然后改成最简单的也不行,后来网上搜罗了一下...

学无止境 2万+

运行bash文件报错 syntax error near unexpected token '$'do\r''

在pycharm上直接写了一个sh文件,到服务器上面运行就报错,错误如标题。 then,在服务器上vim把所有的换行,空格删掉重打无效 最后,总结了错误原因以及两种解决方式。 原因: 其实很多博客讲了,因为windows和linux系统换行符的不同,在windows中换行符是'\r\n',而在linux中只有'\n',现在我们就明白报错的意义了, windows格式写的代码放到linux执...

lwgkzl的博客 9237

运行shell脚本报错:“syntax error near unexpected token 的解决方法”

运行shell脚本报错:“syntax error near unexpected token 的解决方法” 今天写了个Cshell脚本,运行报错syntax error near unexpected token `,脚本语法没有问题,最后发现了问题 用命令vi -b 打开你的SHELL脚本文件,你会。发现每行脚本最后多了个^M。 1 老式的电传打字机使用两个字符来另起新行。一个字符把滑动架移回...

qq_43274859的博客 5524

: syntax error near unexpected token `done'

今天在cygwin中shell奇怪的错误: syntax error near unexpected token `done' 脚本如下: #!/bin/bash #riqizizeng datebeg=$1 dateend=$2 #read datebeg #read dateend beg_s=`date -d "$datebeg" +%s` echo "$beg_s" end_s=`da

wenlong237的专栏 7757

【Solved】syntax error near unexpected token done

syntax error near unexpected token `done’ 运行脚本文件出现syntax error near unexpected token `done’的问题 搜索发现很多答案给出的都是win 和linux 编码解码问题 如果是编码问题用方案1解决 : 脚本如下: #!/bin/bash #riqizizeng datebeg=$1 dateend=KaTeX parse error: Expected 'EOF', got '#' at position 3: 2 #̲re

weixin_43988131的博客 9667

linux执行SHELL脚本报错“syntax error near unexpected token `in”解决

用命令vi -b 打开你的SHELL脚本文件,你会。发现每行脚本最后多了个^M。  那么接下来就要搞清楚这个^M是什么东东?  long long ago.....  老式的电传打字机使用两个字符来另起新行。一个字符把滑动架移回首位 (称为回车,,ASCII码为0D),另一个字符把纸上移一行 (称为换行, ,ASCII码为0A)。当计算机问世以后,存储器曾经非常昂贵。有些人就认定没必要用两个字符来

zhuqinwu的专栏 7993

shell脚本报错"expr: syntax error" 解决方案

几天前写了个shell脚本,在自己本地测试服务器上运行正常,在线上服务器环境,运行报错syntax error near unexpected token `,左看右看shell脚本没有问题,没有办法google搜索,发现一位仁兄转载的讲的挺好,拿来记录一下。内容如下: 用命令vi -b 打开你的SHELL脚本文件,你会。发现每行脚本最后多了个^M。   那么接下来就要搞清楚这个^M是什么东东

wulantian的专栏 3万+

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

转自:http://blog.youkuaiyun.com/xyp84/article/details/4435899     今天写了个shell脚本,在自己机器上运行正常,给同事,运行报错syntax error near unexpected token `,左看右看shell脚本没有问题,没有办法google搜索,发现一位仁兄讲的挺好,内容如下:       用命令vi -b 打开你的SHELL脚

数学屌丝走在it的道路上 1257

Linux运行shell脚本时报错"syntax error near unexpected token `$'\r''

Linux运行shell脚本时,常常会发生syntax error near unexpected token `$'\r''或者syntax error: unexpected end of file等,诸如此类的报错信息出现的原因是因为在编写脚本内容时,在windows上操作,一些回车符或TAB符在Linux系统中是识别不了的。 当出现这类问题时,可以通过vi/vim 加-b参数可以看出文件中的回车符是否正常 # vim -b test.sh 在文件中,如果是Windows的字符会显示为 ' ^

hotkoko的博客 4506

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

shell编程报错:“syntax error near unexpected token `” 今天写了个shell脚本,在自己机器上运行正常,给同事,运行报错syntax error near unexpected token `,左看右看shell脚本没有问题,没有办法google搜索,发现一位仁兄讲的挺好,内容如下: 用命令vi -b 打开你的SHELL脚本文件,你会。发现...

weixin_30887919的博客 209
上一篇: Linux framebuffer显示bmp图片
下一篇: 几个小型 bash 例子
xianjian_x
博客等级 码龄14年 231粉丝 43原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值