Hash (#) before command in bash/fish

Hi all, :wave:

I just want to ask you a general question regarding the correct understanding of how a shell works. :blush:

I am using fish but with bash itΒ΄s the same as it turns out.


On my system I have installed gedit, the text-editor. If I put a hash before the command in the terminal, like so: #gedit or even so: # gedit
and then push β€œenter” nothing happens. The command is simply ignored.

The return value is zero; so everything should be o.k.

I know in bash scripting the hash marks everything that follows as comments, so I presume in a terminal this should work the same way. :thinking:

Is this behaviour to be expected :question:

I hope so as this gives me the opportunity to quickly punch in some short-term note I donΒ΄t want to forget for a restricted period of time.
That would be very convenient for me as I always have a terminal (ore more of them) open.

I guess the relevant part of the bash man-pages would be this:

In a non-interactive shell, or an interactive shell in which the interactive_comments option to the shopt builtin is
enabled (see SHELL BUILTIN COMMANDS below), a word beginning with # causes that word and all remaining characters on
that line to be ignored.

What might be your opinion on this?

Thanks a lot for your help in advance.

Many greetings
Rosika :slightly_smiling_face:

Hi @Rosika,

Is there something else you were trying to do beside start gedit?
I installed gedit, I went to the command line, I type in β€˜gedit’ (by itself), and up comes the editor.
This was on Mint.


1 Like

Running something interactively in the shell is almost the same as if you would run a script. The difference is, that a script is usually expected to work on its own, so user input is not desired, as well as colour coding is usually unnecessary or sometimes even cumbersome, in non-interactive scenarios.
However, besides these exceptions, running something as a script in a file and running the same in a terminal should pretty much always lead to the same results.

Maybe the following puts it more to a point.

If you run a script, it runs through bash (or fish).
If you type and execute something inside bash, then it’s run through bash, just like the script.
There are only some little exceptions, I hinted above.

You could also write a program or script that automatically creates a file with the content you specify, which you can use for super quick note taking.

1 Like

Hi all, :wave:

thanks so much for your replies. :heart:


Thanks Howard for your comment.
IΒ΄m afraid there has been a misunderstanding.

In actual fact I didnΒ΄t want to start gedit. This was just an example. I couldΒ΄ve chosen any other command for that matter.
Sorry if I was a bit unclear about that. :slightly_frowning_face:

I just wanted to know whether putting a hash in front of any command would be regarded as a command by the shell.
And @Akito confirmed that in his reply.

Thanks again.


Thanks so much, Akito.

I was more or less assuming that but really wanted to have a confirmation on that.
So thanks a lot.

fish seems to see to it that different scenarios are color-coded: :wink:



The three screenshots represent:

  • running gedit # gedit is installed, therefore blue
  • gedit as a comment # does nothing therefore dark red
  • trying to run kate # kate is not installed therefore light red

ThatΒ΄s what I wanted to know, thanks.
So my presumptions were correct then. IΒ΄m glad. :smile:

Thanks for the suggestion. IΒ΄ll think about it.

Well, Lubuntu also has qlipper installed by default, which gives me the opportunity to quickly create sticky notes.
However puchnig something into a terminal seems most convenient to me as I always have a terminal window open on each of my 4 virtual desktops… :wink:

Thanks so much for your explanation, Akito.

Many greetings to you all.
Rosika :slightly_smiling_face:


Hi Rosika,
It works in my Debian. I can even do #! /bin/bash, and it treats it as a comment interactively. In a script, that at the first line would do something.

What I do for a note in a terminal is
cat > junk
then I can keep it if I want.


1 Like

It’s just there, so the operating system can decide what interpreter should be launched, when the script is launched neutrally, as in the following example.

chmod +x scripty.sh
1 Like

Hi @nevj and @Akito, :wave:

Thanks for your replies. :heart:

Thanks for your confirmation. Neville.

Right. That looks like a good solution. But if you want lo take a look at it youΒ΄de have to fire up β€œjunk”, right?
In most cases I just have to take a look at some words or numbers or whatever.
So quickly punching them into an already opened terminal seems quite convenient for me. :blush:

Quite. ItΒ΄s called the shebang if I remember correctly…

Many greetings
Rosika :slightly_smiling_face:

No, what you type would be on the screen too… until it scrolls off… just like your #

 ItΒ΄s called the shebang if I remember correctly…

I think that is a corruption of hash-bang

I just tried to fool it, but I could not.

Some sort of notepad or clipboard is probably better

1 Like

Thanks Neville, :heart:

In fact you solution is better. :+1:
First I was going to say: punching something in with a preceding hash at least gives me my prompt back.
But applying your solution does the same as soon as I finish my note-taking with ctrl+D.
Plus: readabilty is much better as itΒ΄s not colour-coded.


rosika@rosika-10159 ~> cat > junk
This is a text.
This is it.
rosika@rosika-10159 ~> bat junk 
       β”‚ File: junk
   1   β”‚ This is a text.
   2   β”‚ This is it.

Thanks a lot, Neville.

Many greetings from Rosika :slightly_smiling_face:

1 Like