5

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?

1
  • 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: github.com/hkbakke/bash-insulter
    – michael
    Commented Feb 17, 2021 at 7:36

2 Answers 2

8

Yes.

Further reading

2

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .