I just want to ask you a general question regarding the correct understanding of how a shell works.
I am using fish but with bash itΒ΄s the same as it turns out.
Example:
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.
Is this behaviour to be expected
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.
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.
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.
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.
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.
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.
O.K.
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β¦
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.
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.
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.
Quite. ItΒ΄s called the shebang if I remember correctlyβ¦
In fact you solution is better.
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.
Example:
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.
ββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ