bashshell

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"?

I always have to use an option when I execute this command on shell (mosquitto), and I want to skip it. Mosquitto is a message broker, so it keeps listening. 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:

#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. I also have tried to add ">&1" but it doesn't work, and I think that it's because the command doesn't end.


Solution

  • Maybe an alias is enough for you ? If you add this into your .bashrc file

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

    (don't forget to reload your .bashrc file)

    Then typing youraliasname should do what you expect.

    Edit : you can also just type the alias command to define and try the alias without editing your .bashrc. Use unalias youraliasname to remove it after.