Monday, May 6, 2024
 Popular · Latest · Hot · Upcoming
21
rated 0 times [  21] [ 0]  / answers: 1 / hits: 2641  / 1 Year ago, mon, may 15, 2023, 11:58:45

When bash encounters an unknown command(word?) it does this :



The program 'hello' can be found in the following packages:
* hello
* hello-debhelper
Try: sudo apt-get install <selected package>


what I would like to know is how this is done so I can edit it or add something before it to cross check the unknown word from a home grown dictionary which would have phrase:reply pairs that can then be sent to output.



I am guilty of not looking enough for it around .. but the few bash guides I tried digging up didn't have anything on this. Maybe I am looking at the wrong places .. any pointers?



And yes I am doing this so every time I type wtf when a program fails , I want something nice thrown back at me...


More From » bash

 Answers
2

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
}

[#42478] Tuesday, May 16, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
torlim

Total Points: 408
Total Questions: 113
Total Answers: 110

Location: Estonia
Member since Wed, May 27, 2020
4 Years ago
;