3

I'd like to define a function that is called, whenever a shell-user types a command that does not exist. In my case I'd like to log the errors and try alternative commands.

currently, when typing e.g. dgfgsdjagfghsdg the error zsh: command not found: dgfgsdjagfghsdg is shown.

Is there a way to define a function, that get the typed command (+ arguments) as a parameter?

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Edward
  • 285
  • 1
  • 5
  • 8
  • for example & for reference, here's a bash/zsh handler that prints out a random insult whenever the user types in a command that does not exist: https://github.com/hkbakke/bash-insulter – michael Feb 17 '21 at 07:36

2 Answers2

6

Yes.

Further reading

JdeBP
  • 66,967
  • 12
  • 159
  • 343
0

To complement JdeBP's answer, in the fish shell it's called fish_command_not_found.

thiagowfx
  • 1,221
  • 11
  • 20