问题记录:Ubuntu中source运行.sh shell脚本报错:command not found 未找到命令

问题截图:
问题记录:Ubuntu中source运行.sh shell脚本报错:command not found 未找到命令_第1张图片
一开始,我以为是权限的问题,root之后仍然报错

解决方法:
我解决这个问题分了两步
1.修改了/bin/bash执行方式:

ls -l `which sh`

会发现脚本默认是以dash模式执行的,此时运行:

dpkg-reconfigure dash

就会出现:
在这里插入图片描述
2.做完上述步骤,仍然报错,此时便要考虑是脚本本身格式问题。我是从Win10主机复制到虚拟机里面的,于是进行如下操作
安装dos2unix组件

apt install dos2unix

对.sh脚本进行格式转换

chmod 755 your_script.sh
dos2unix your_script.sh

做完这些后,就可以正常source我们的.sh脚本了

参考链接:
https://www.jianshu.com/p/44d659fcbf09
https://blog.csdn.net/Together_CZ/article/details/88395718?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.edu_weight&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.edu_weight

你可能感兴趣的:(问题记录)