问题: bash function 中有部分需要sudo运行,如何定义
参考:https://serverfault.com/questions/177699/how-can-i-execute-a-bash-function-with-sudo?newreg=de7619fc54fe4547bd3e8af0647b860d
参考:https://serverfault.com/questions/177699/how-can-i-execute-a-bash-function-with-sudo?newreg=de7619fc54fe4547bd3e8af0647b860d
1 #!/bin/bash
2 #function run with sudo
3
4 function Hello() {
5 echo "Heeeeeello, $1"
6 whoami
7 }
8
9 hello(){
10 echo "hi,$1"
11 }
12
13 hello nosudo
14 sudo_password="sudo_password"
15 echo "${sudo_password}"|sudo -S su root -c "$(declare -f Hello); Hello start"
$ help declare
Options:
-f restrict action or display to function names and definitions
没有评论:
发表评论