linux sbin目录坏掉,解决Linux环境下执行脚本时报错:/bin/bash^M: 坏的解释器: 没有那个文件或目录...

文章目录

[隐藏]

一、问题描述

二、错误原因

三、修改错误

四、附录

一、问题描述

我在Windows 10 系统下编辑了一个发送消息到企业微信的shell脚本文件,然后copy到了远程的Linux服务器,当运行的时候报错了。如下所示:

0f396a225bbbecfec3342fc4a2505760.png

root@ubuntu116:/data/gitlabData/auto_back_shell# ./qiyewechat-notifier.sh -bash: ./qiyewechat-notifier.sh: /bin/bash^M: 坏的解释器: 没有那个文件或目录 root@ubuntu116:/data/gitlabData/auto_back_shell#

二、错误原因

这个文件在Windows 下编辑过,在Windows下每一行结尾是nr,而Linux下则是n,所以才会有 多出来的r。

三、修改错误

使用指令sed -i 's/r$//' xxxxxxx.sh,上面的指令会把 xxxxxxx.sh 中的r 替换成空白!

实操一下:

739c8582ae9ba55413210254565eda5d.png

root@ubuntu116:/data/gitlabData/auto_back_shell# sed -i 's/r$//' qiyewechat-notifier.sh 您在 /var/mail/root 中有新邮件 root@ubuntu116:/data/gitlabData/auto_back_shell# ./qiyewechat-notifier.sh -h ./qiyewechat-notifier.sh: 非法选项 -- h Usage: qiyewechat.sh [-u USER] [-t TITLE] [-c CONTENT] [-d DETAIL] [-p PICTURE] Description: USER, 用户. TITLE, 标题. CONTENT, 内容. DETAIL, 细节. PICTURE, 图片. root@ubuntu116:/data/gitlabData/auto_back_shell#

如上所示,执行了下面的脚本之后,

sed -i 's/r$//' qiyewechat-notifier.sh

qiyewechat-notifier.sh就可以正常运行了!

四、附录

qiyewechat-notifier.sh的部分代码如下所示:

55a347e1e49fc031565deaf5a4cfc31f.png

#!/bin/bash #用法提示 usage() { echo "Usage:" echo " qiyewechat.sh [-u USER] [-t TITLE] [-c CONTENT] [-d DETAIL] [-p PICTURE]" echo "Description:" echo " USER, 用户." echo " TITLE, 标题." echo " CONTENT, 内容." echo " DETAIL, 细节." echo " PICTURE, 图片." exit -1 } # 获取脚本执行时的选项 while getopts u:t:c:d:p: option do case "${option}" in u) USER=${OPTARG};; t) TITLE=${OPTARG};; c) CONTENT=${OPTARG};; d) DETAIL=${OPTARG};; p) PICTURE=${OPTARG};; h) usage;; ?) usage;; esac echo $option echo $OPTARG done

原文出处:csdn -> https://blog.csdn.net/ouyang_peng/article/details/86488451

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值