![在 sudo su 之后,使用 bash 和 curl 调用的 shell 脚本上的函数抛出了“命令未找到”错误](https://linux22.com/image/738109/%E5%9C%A8%20sudo%20su%20%E4%B9%8B%E5%90%8E%EF%BC%8C%E4%BD%BF%E7%94%A8%20bash%20%E5%92%8C%20curl%20%E8%B0%83%E7%94%A8%E7%9A%84%20shell%20%E8%84%9A%E6%9C%AC%E4%B8%8A%E7%9A%84%E5%87%BD%E6%95%B0%E6%8A%9B%E5%87%BA%E4%BA%86%E2%80%9C%E5%91%BD%E4%BB%A4%E6%9C%AA%E6%89%BE%E5%88%B0%E2%80%9D%E9%94%99%E8%AF%AF.png)
执行时:
#!/bin/bash
function01() {
echo "Func01"
}
function02() {
echo "Func02"
}
function03() {
echo "Func03"
}
clear
function01
function02
#sudo su
function03
并调用如下:
curl http://192.168.1.1:80/myScript.sh | sudo bash
或者
curl http://192.168.1.1:80/myScript.sh | bash
它运行正常但如果取消注释该行:
#sudo su
然后它会引发错误:
bash: line 1: function03: command not found