如何在Shell中更改命令?

时间:2020-10-07 09:51:09

标签: bash shell

当我在shell中写“ mosquitto”时,我认为我写了“ mosquitto -c /etc/mosquitto/conf.d/mosquitto.conf”怎么办?

在shell(mosquitto)上执行此命令时,我总是必须使用一个选项,而我想跳过它。 Mosquitto是一个消息代理,因此一直在监听。当我执行

mosquitto -c /etc/mosquitto/conf.d/mosquitto.conf

终端看起来像这样:

manuel@Manuel:~$ mosquitto -c /etc/mosquitto/conf.d/mosquitto.conf
1602063783: mosquitto version 1.4.15 (build date Tue, 18 Jun 2019 11:42:22 -0300) starting
1602063783: Using default config.
1602063783: Opening ipv4 listen socket on port 1883.
1602063783: Opening ipv6 listen socket on port 1883.

它并没有结束。

因此,我寻找了一种解决方案,该方案修改了“ .bashrc”文件并添加了如下功能:

#Using mosquitto with local conf
function mosquitto
{
    mosquitto -c /etc/mosquitto/conf.d/mosquitto.conf $@ 
}

但是使用此功能,输出不会显示在shell中。我也曾尝试添加“>&1”,但是它不起作用,我认为这是因为命令没有结束。

1 个答案:

答案 0 :(得分:2)

也许别名就足够了吗?如果将此添加到您的.bashrc文件中

aws autoscaling describe-auto-scaling-groups --query 'AutoScalingGroups[?DesiredCapacity>=`3`].[AutoScalingGroupName,DesiredCapacity,MinSize,MaxSize]' --output table --profile MyProfile

(不要忘记重新加载您的.bashrc文件)

然后输入alias youraliasname='mosquitto -c /etc/mosquitto/conf.d/mosquitto.conf' 应该可以完成您的期望。

编辑:您也可以直接键入alias命令来定义和尝试别名,而无需编辑.bashrc。之后使用youraliasname删除它。