Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

There is a question about overriding the default command not found behavior on Ubuntu. It is Here. I tried adding the following to ~/.bash_profile, /etc/bashrc and /etc/profile, but no luck:

function command_not_found_handle {
  echo "oops!"
}

How can I do the exact same thing in OS X?

share|improve this question
    
Try adding it to either ~/.bashrc or /etc/bash.bashrc. –  terdon Apr 6 '13 at 17:51

1 Answer 1

It's not some feature of bash or OS X as clearly implied in the referenced article. As evidence, you also have "I deleted my /etc/bash.bashrc". In other words, nothing is calling the handle on your system and hence no effect.

You need to get the source of that package and compile (or even port, but there may be equivalents) it on OS X. Then you would add the if (below) to the default bash profile on OS X, which should be somewhere in /etc.

Part of /etc/bash.bashrc from Ubuntu

# if the command-not-found package is installed, use it
if [ -x /usr/lib/command-not-found -o -x /usr/share/command-not-found ]; then
    function command_not_found_handle {
            # check because c-n-f could've been removed in the meantime
                if [ -x /usr/lib/command-not-found ]; then
           /usr/bin/python /usr/lib/command-not-found -- $1
                   return $?
                elif [ -x /usr/share/command-not-found ]; then
           /usr/bin/python /usr/share/command-not-found -- $1
                   return $?
        else
           return 127
        fi
    }
fi
share|improve this answer
    
The "package" may be a bash hack or patch and not some kernel-level extension as I thought when writing the answer. If that is the case, your chances of replicating the desired effect are much greater. –  Ярослав Рахматуллин Apr 6 '13 at 22:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.