How do I teach bash in Ubuntu some curse words?

Look in your /etc/bash.bashrc for the command_not_found_handle function definition.

If you want to remove that behaviour, put this in your .bashrc

[[ $(type -t command_not_found_handle) = "function" ]] && 
  unset -f command_not_found_handle

If you want to customize, you can do

# see http://stackoverflow.com/questions/1203583/how-do-i-rename-a-bash-function
alias_function() {
  eval "${1}() $(declare -f ${2} | sed 1d)"
}

alias_function orig_command_not_found_handle command_not_found_handle 

command_not_found_handle() {
  command=$1
  shift
  args=( "$@" )

  do your stuff before
  orig_command_not_found_handle "$command" "${args[@]}"
  do your stuff after
}

This might be potentially useful...

The command-not-found package is what gives you the magic response. I'm not sure if it's possible to customize it, but it might be worth a look.

Another option to do what I think what you're trying to do would be to add an alias to your .bashrc file that prints a message whenever you type 'wtf' or something like that:

alias wtf='echo "chill out man"'

Add this to your ~/.bashrc file, and then do: source $HOME/.bashrc

This would then just print a message whenever you type wtf into your terminal. You could also make this alias call a script that prints a more detailed message or something similar. The possibilities are endless!


This behavior is defined in the system-wide Bash configuration file, /etc/bash.bashrc:

# 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

To customize it, simply override this function in your own ~/.bashrc:

function command_not_found_handle {
  echo "Sorry, smotchkiss, try again."
}