这是一个小的 .bashrc 别名,可以让我看到启动服务的结果
alias systemctl start apache='systemctl start apache && echo SUCCESS || echo failure'
我如何修改以使用所有systemctl start
命令?
答案1
不要使用别名。使用外壳函数。像这样
function sysctl_start {
systemctl start "$1" && echo SUCCESS || echo FAILURE
}
甚至更好
function sysctl_start {
systemctl start "$1"
systemctl status "$1"
}
如果您只想对启动进行特殊处理,但保留名称,请编写一个包装器
function systemctl {
if [ "$2" = start ]; then
shift
/usr/bin/systemctl start "$@" && echo "SUCCESS" || echo "FAILURE"
else
/usr/bin/systemctl "$@"
fi
}