简体   繁体   English

如何在shell中更改命令?

[英]How can I change a command in shell?

How can I do that when I write "mosquitto" in shell, it thinks that I wrote "mosquitto -c /etc/mosquitto/conf.d/mosquitto.conf"?当我在 shell 中写“mosquitto”时,它认为我写的是“mosquitto -c /etc/mosquitto/conf.d/mosquitto.conf”怎么办?

I always have to use an option when I execute this command on shell (mosquitto), and I want to skip it.当我在 shell (mosquitto) 上执行此命令时,我总是必须使用一个选项,我想跳过它。 Mosquitto is a message broker, so it keeps listening. Mosquitto 是一个消息代理,所以它一直在监听。 When I execute当我执行

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

the terminal look like this:终端看起来像这样:

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.

and it doesn't end.它并没有结束。

So I looked for a solution that was modifying the ".bashrc" file and adding a function like this:所以我寻找了一个修改“.bashrc”文件并添加如下函数的解决方案:

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

But with this function, the output doesnt show in shell.但是使用此功能,输出不会显示在 shell 中。 I also have tried to add ">&1" but it doesn't work, and I think that it's because the command doesn't end.我也尝试添加 ">&1" 但它不起作用,我认为这是因为命令没有结束。

Maybe an alias is enough for you ?也许别名对你来说就足够了? If you add this into your .bashrc file如果您将其添加到 .bashrc 文件中

alias youraliasname='mosquitto -c /etc/mosquitto/conf.d/mosquitto.conf'

(don't forget to reload your .bashrc file) (不要忘记重新加载您的 .bashrc 文件)

Then typing youraliasname should do what you expect.然后输入youraliasname应该youraliasname您的期望。

Edit : you can also just type the alias command to define and try the alias without editing your .bashrc.编辑:您也可以只输入别名命令来定义和尝试别名,而无需编辑您的 .bashrc。 Use unalias youraliasname to remove it after.使用unalias youraliasname将其删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM