firewall-cmd --add-service 的 bashrc 函数

bashrc function for firewall-cmd --add-service

如何在 bashrc 中创建一个名为 fadd() 的别名函数,它将服务名称作为参数并执行 firewall-cmd --permanent --add-service=$argument?

你不能真正拥有 "alias functions",因为别名显然不是函数;他们只是这样做(来自 manual):

The first word of each simple command, if unquoted, is checked to see if it has an alias. If so, that word is replaced by the text of the alias.

如果没有丑陋的技巧,就不可能为别名使用参数。要定义函数,您可以将其添加到 .bashrc:

fadd () {
    firewall-cmd --permanent --add-service=""
}

然后用 fadd service 调用它,以获得任何你想要的 service