bash函数 & user 代行
bash函数
将函数追加写入~/.bashrc
文件即可持久化,否则只在当前shell session内有效,关闭即无效
不要忘记加完需要
source ~/.bashrc
才会生效
function functionName {
<commands>
}
例子:
function f1 {
echo "Hello I'm function 1"
echo "Bye!"
}
linux下root用户指定user执行操作
sudo -H -u otheruser bash -c 'echo "I am $USER, with uid $UID"'
-H 可选,使用
bash -c xxx
可执行多条命令,单个命令可直接跟user参数后面
reference
Updated: 2022-12-06 22:57
Created: 2022-07-07 16:00