zsh Interpret/ignore commands beginning with ‘#’ as comments

In bash, if I type a command beginning with a '#', bash ignores it as a comment.

Ie, the following is ignored at the bash prompt:

> # Hi there!

Whereas in zsh:

> # Hi there !
zsh: bad pattern: #

How can I ask zsh to do the same?

This is incredibly useful to “store” commands that you want to run later, or to chat when using a shared tmux/screen session.

I am using ‘oh my zsh

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Check if the INTERACTIVE_COMMENTS option is set.

According to this page, “[…] in interactive shells with the INTERACTIVE_COMMENTS option set, […] # causes that word and all the following characters up to a newline to be ignored.”


According to the comments were added later, set -k does exactly the same thing.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x