Ubuntu运行.sh脚本文件报错:bash: ./your_file_name.sh: /bin/bash^M: 解释器错误: 没有那个文件或目录


一、运行.sh脚本报错: /bin/bash^M: 解释器错误: 没有那个文件或目录

这个^M是windows下的结尾\r,到linux系统中就变成了 ^M。
因为我是把.sh脚本从windows下移动到虚拟机中,导致了这个问题。
使用

cat -A compare-tcp-algorithms.sh 

-A :相当于 -vET 的整合选项,可列出一些特殊字符而不是空白而已;
查看脚本文件的内容.

-algorithms.sh 
#!/bin/bash^M$
^M$
#  MIT License^M$
# ^M$
#  Copyright (c) 2017 haltaro^M$
#  ^M$
#  Permission is hereby granted, free of charge, to any person obtaining a copy^M$
#  of this software and associated documentation files (the "Software"), to deal^M$
#  in the Software without restriction, including without limitation the rights^M$
#  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell^M$
#  copies of the Software, and to permit persons to whom the Software is^M$
#  furnished to do so, subject to the following conditions:^M$
#  ^M$
#  The above copyright notice and this permission notice shall be included in all^M$
#  copies or substantial portions of the Software.^M$
#  ^M$
#  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR^M$
#  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,^M$
#  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE^M$
#  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER^M$
#  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,^M$
#  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE^M$
#  SOFTWARE.^M$
#^M$
#  Author: haltaro <github.com/haltaro>^M$
#  Reseacher at a Japanese company. His reseach interests are related to^M$
#  network architectures, protocols, traffic control, mathematical modeling,^M$
#  optimization, machine learning, and shiba dog :-)^M$
^M$
ALGORITHMS=(TcpNewReno TcpHighSpeed TcpHybla TcpWestwood TcpWestwoodPlus TcpVegas TcpScalable TcpVeno TcpBic TcpYeah TcpIllinois TcpHtcp)^M$
^M$
for item in ${ALGORITHMS[@]}; do^M$
  echo "----- Simulating $item -----"^M$
  ./waf --run "my-tcp-variants-comparison --transport_prot=$item --prefix_name='data/$item' --tracing=True --duration=20"^M$
done^M$
^M$
./plottcpalgo.py^M$

可看到结尾都有^M。需要把它们去掉。

sed -i 's/\r$//' compare-tcp-algorithms.sh 
-algorithms.sh 
#!/bin/bash$
$
#  MIT License$
# $
#  Copyright (c) 2017 haltaro$
#  $
#  Permission is hereby granted, free of charge, to any person obtaining a copy$
#  of this software and associated documentation files (the "Software"), to deal$
#  in the Software without restriction, including without limitation the rights$
#  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell$
#  copies of the Software, and to permit persons to whom the Software is$
#  furnished to do so, subject to the following conditions:$
#  $
#  The above copyright notice and this permission notice shall be included in all$
#  copies or substantial portions of the Software.$
#  $
#  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR$
#  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,$
#  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE$
#  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER$
#  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,$
#  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE$
#  SOFTWARE.$
#$
#  Author: haltaro <github.com/haltaro>$
#  Reseacher at a Japanese company. His reseach interests are related to$
#  network architectures, protocols, traffic control, mathematical modeling,$
#  optimization, machine learning, and shiba dog :-)$
$
ALGORITHMS=(TcpNewReno TcpHighSpeed TcpHybla TcpWestwood TcpWestwoodPlus TcpVegas TcpScalable TcpVeno TcpBic TcpYeah TcpIllinois TcpHtcp)$
$
for item in ${ALGORITHMS[@]}; do$
  echo "----- Simulating $item -----"$
  ./waf --run "my-tcp-variants-comparison --transport_prot=$item --prefix_name='data/$item' --tracing=True --duration=20"$
done$
$
./plottcpalgo.py$

重新运行,成功

在这里插入图片描述

二、总结

使用下面语句即可:

sed -i 's/\r$//' your_file_name.sh 
  • 6
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值