Is executing a line, beginning with a hash-tag, like #something, in a terminal, dangerous?

Something like:

usr@machine:~$ #something

Or in a multi-line manner:

usr@machine:~$ <<something
> 1
> 2
> 3
> something

As I understand that's just a comment in bash; but wanted to be sure how it works in a terminal.

Why? The reason I do this; is that I want to use the command line history itself, for note-taking! I've set HISTSIZE, HISTFILESIZE and HISTTIMEFORMAT in .bashrc and it works just fine. This way, I can see my notes, alongside my commands, in a meaningful order, in time. I have some simple personal note-taking style that is getting parsed using a simple script.

  • 1
    As you self already stated it is a comment and stays a comment, nothing dangerous with that.
    – Videonauth
    Apr 28, 2016 at 8:57
  • Thanks @Videonauth! I was not sure if the command line syntax is identical to that one of a bash script. Apr 28, 2016 at 9:00
  • For your uses, the script command might be helpful too.
    – Arronical
    Apr 28, 2016 at 9:27
  • I wonder if there's a way to get a newline recognized in a comment... that would make some comments no longer safe, but I don't suspect it's possible
    – Xen2050
    Apr 28, 2016 at 10:46
  • 1
    I was thinking of a single line that starts with # and looks like a comment, but contained some dangerous code later on, along the lines of your "Is a comment dangerous" first line. FYI, the <<word redirections are in man bash under Redirection -> Here Documents. It's not crystal clear (quoting any characters in word means something) but should be helpful
    – Xen2050
    Apr 28, 2016 at 12:48

1 Answer 1


Well, to make it official here is your answer.

As you already stated a comment line is a comment line, this wont even change if you enter one directly in terminal. This counts as well for lines beginning with #!, they are simply only comments for the shell/terminal when typed in by hand.

Another option could be to echo your comment directly into the `.bash_history' like this.

echo "# i am a comment to be saved" >> ~/.bash_history

Of course this would be a lot of typing each time, but this would even allow you to make multi-line comments with echo -e, here an example:

echo -e "# line 1 comment\n# line 2 comment" >> ~/.bash_history

Another option for making multi-line comments would be the following:

cat >> ~/.bash_history << "EOF"
># line 1 comment
># line 2 comment

This way the lines with comments will get added and you end the input with typing EOF, thats as well pretty useful if you have systems where you have no editor at hand. You will keep adding lines till you input EOF which not gets recorded.

  • Thanks! Does that apply to #! too? Are there other things that one might be aware of? Apr 28, 2016 at 10:37
  • @KavehShahbazian If you mean a shebang example #!/bin/bash? This is aswell in this case only a comment for the shell/terminal.
    – Videonauth
    Apr 28, 2016 at 10:39
  • Sorry; I've added the multiline too. Would you please cover that too so this answer gets marked as answer? Thank; Apr 28, 2016 at 11:52
  • @KavehShahbazian no proplem, covered that too now.
    – Videonauth
    Apr 28, 2016 at 11:56

You must log in to answer this question.

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