sudo执行shell中自定义函数

  sre

#!/bin/bash

function me()
{
echo "im (whoami) "
}

# Test that it works.
me
sudo -u test whoami
sudo -u test me
FUNC=(declare -f me)
sudo -u test bash -c "FUNC; me"
me

#sudo -u test bash -c "(declare -f me); me"


[root@server ~]# ./test.sh
im root
test
sudo: me: command not found
im test
im root

LEAVE A COMMENT

Captcha Code