Read more

"command not found" bash function

Kim Klotz
September 14, 2012Software engineer at makandra GmbH

If you type a command in your bash that doesn't exist you get this:

bash: foo: command not found
Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

or if you have installed the command-not-found package on ubuntu/debian:

The program 'foo' can be found in the following packages:
* foobar
* barfoo
Try: sudo apt-get install <selected package>
-bash: foo: command not found

But you can customize this with the command_not_found_handle function which you can add to your .bashrc.

This is something I've tried:

function command_not_found_handle {
  ssh $@
}

Now I just have to type hostnames and get connected with ssh. Because I'm using $@ I can also use options like a custom ssh-port.

Posted by Kim Klotz to makandra dev (2012-09-14 12:33)