Ubuntu运行.sh脚本文件报错:bash: ./your_file_name.sh: /bin/bash^M: 解释器错误: 没有那个文件或目录
文章目录一、运行.sh脚本报错: /bin/bash^M: 解释器错误: 没有那个文件或目录二、总结一、运行.sh脚本报错: /bin/bash^M: 解释器错误: 没有那个文件或目录这个^M是windows下的结尾\r,到linux系统中就变成了 ^M。因为我是把.sh脚本从windows下移动到虚拟机中,导致了这个问题。使用cat -A compare-tcp-algorithms.sh-A
·
一、运行.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
更多推荐
已为社区贡献2条内容
所有评论(0)