Linux下执行sh脚本 提示command not found解决办法

Keva
阅读 3,094

执行sh脚本时出现错误:command not found

确保用户对文件有读写及执行权限

chmod a+x test.sh

如以上未解决,尝试一下下面的方法

修改文件格式(如果是从winodws搬过来的会显示dos格式,要把它改成unix格式)

(1)使用vi或vim工具

vi test.sh

(2)利用如下命令查看文件格式

:set ff 或 :set fileformat

可以看到如下信息

fileformat=dos 或 fileformat=unix

(3)利用如下命令修改文件格式  

:set ff=unix 或 :set fileformat=unix  
:wq (存盘退出)

3、最后再执行sh脚本文件

./test.sh
回到顶部