8

Is there a way to intercept the "command not found" error in ZSH? I've seen this is possible in bash apparently, but I couldn't find anything about doing it in zsh.

1 Answer 1

10

There is; it's the same as in bash, you make a function named command_not_found_handler. It'll be passed all the arguments that were given in the shell

$ foobar baz
zsh: command not found: foobar
$ function command_not_found_handler() {echo "You tried to run $1 with arg $2";}
$ foobar baz
You tried to run foobar with arg baz
0

You must log in to answer this question.

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