最近在学shell脚本编写,在windows上编写完之后,通过xshell上传到linux系统,赋予执行权限之后,执行脚本出现command not found
原因是:.sh脚本在windows系统下用记事本编辑的,不同系统的编码格式引起的错误。
解决:1:首先确保用户对该文件有读和写以及执行的权限
chmod +x test.sh
2:修改文件格式
vim test.sh
利用如下命令查看文件格式
:set ff
或者用
:set fileformat
当执行:set ff或者:set fileformat会出现fileformat=unix或者是fileformat=dos
3:利用如下命令修改文件格式
:set ff=unix 或者 :set fileformat=unix
4:保存并退出
:wq!
5:在次查看文件格式
5:执行脚本