我想在此 bash 函数中间脚本中启用 sudo。我认为问题是 sudo -s
打开了一个新的 shell,并且所有后续行都没有打印,因为 shell 已退出。
function example {
echo "one"
sudo -s
echo "two"
echo "three"
}
如何让 two
和 three
也打印为 sudo?没有在每个之前添加 sudo
?
最佳答案
双重功能呢?这有帮助吗?
#!/bin/bash
function test2 {
sudo echo "two"
sudo echo "three"
}
function test {
echo "one"
test2
}
test
关于linux - 如何在不离开当前 shell 的情况下在当前 shell 中间脚本中设置 sudo?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48191955/