5

Is there a way to suppress the command not found error in MacOS/ zsh for a command typed after hash # symbol?

Typically, any command typed after # is ignored in Ubuntu/bash shell. Is there an easy way to do the same in MacOS/zsh terminal? Or equivalent character to ignore the command without resulting in the error?

Thanks!

1 Answer 1

8

zsh has a shell option, INTERACTIVE_COMMENTS, which is unset (off/disabled) by default, meaning that the # is not treated as a comment character in interactive shells (it's still a comment character for shell script files). You can set it with…

setopt INTERACTIVE_COMMENTS

…or by using its shortcut letter, k

set -k

If you always want this behavior, you can add either of those commands to the appropriate shell startup script for your situation.

bash actually has the same/similar option, but in most bash installations, it's set (enabled) by default. It seems typical zsh installations default to having it unset (disabled).

You must log in to answer this question.

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