得到错误“:找不到命令";尝试运行shell脚本时 [英] Getting error ": command not found" when trying to run shell script
问题描述
我有一个正在尝试运行的脚本,但是每当我尝试运行该脚本时,都会出现错误:not found".这是我尝试修复的方法:
- 确保hashbang是正确的#!/bin/bash"
- 在文件上运行dos2unix
- 以scriptname.sh,./scriptname.sh和/bin/bash scriptname.sh运行脚本
- chmod 755脚本名.sh
我仍然无法运行该脚本.任何帮助深表感谢!
这是由回车引起的.以下是 bash标签Wiki 的摘录:
-
检查您的脚本或数据是否具有DOS样式的行尾字符
-
使用
DOS回车符将在每行后显示为cat -v yourfile
或echo"$ yourvariable" |cat -v
.^ M
.如果找到它们,请使用
dos2unix
(又名fromdos
)或tr -d'\ r'
-
确保检查所有数据,而不仅仅是脚本本身.
I have a script that I'm trying to run but I just get the error ": command not found" whenever I try to run it. Here's what I've tried to do to fix it:
- Made sure the hashbang is correct "#!/bin/bash"
- Run dos2unix on the file
- Run the script as scriptname.sh, ./scriptname.sh, and /bin/bash scriptname.sh
- chmod 755 scriptname.sh
I still am unable to run the script. Any help is much appreciated!
This is caused by carriage returns. Here's the excerpt from the bash tag wiki:
Check whether your script or data has DOS style end-of-line characters
Use
cat -v yourfile
orecho "$yourvariable" | cat -v
.DOS carriage returns will show up as
^M
after each line.If you find them, delete them using
dos2unix
(a.k.a.fromdos
) ortr -d '\r'
Make sure to check all your data, and not just the script itself.
这篇关于得到错误“:找不到命令";尝试运行shell脚本时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!