running cat without a direction

6 Antworten [Letzter Beitrag]
jaisgossman
Offline
Beigetreten: 06/18/2018

I've been messing with my terminal and I've come across something I don't understand. if I run $ cat on it's own, I am booted from any working environment. Can some explain what's going on?

chaosmonk

I am a member!

I am a translator!

Offline
Beigetreten: 07/07/2017

> if I run $ cat on it's own, I am booted from any working environment.
> Can some explain what's going on?

What do you mean by "booted from"? When I run `cat` without any
arguments, it just hangs until I cancel the command with Ctrl+C.

jaisgossman
Offline
Beigetreten: 06/18/2018

cancelling the command, I guess that's what I was indirectly trying to learn here. thanks!

Beformed
Offline
Beigetreten: 01/13/2017

When you call cat without arguments, it expects to get the input from standard input, which means from your keyboard.

jaisgossman
Offline
Beigetreten: 06/18/2018

so is it just waiting for a further command? or is it actually running the cat program somehow?

Magic Banana

I am a member!

Online
Beigetreten: 07/24/2010

'cat' is running. It is waiting for you to type the content to write to the standard output (the terminal, if not redirected) because you have not given it any file(s) in argument(s) and because, as always for POSIX commands, the standard input (the keyboard, if not redirected) is the default. That content is processed line after line (try writing any line, type [Enter], and that line is written to the standard output) until the EOF character (EOF stands for "End Of File") is read (you can input it with Ctrl+D, and the line you started is written to the standard output) or until 'cat' is abruptly interrupted (you can do so with Ctrl+C, which sends the SIGINT signal to the process, and the line you started is NOT written to the standard output).

So, for instance, you can create in the working directory a text file named "test" and containing:
Hello, world!
I am Magic Banana.

(with no newline after the dot) by executing:
$ cat > test
(> redirects the standard output to the file "test") and typing:
Hello, world![Enter]
I am Magic Banana.[Ctrl+D]

To display the two-line content of "test" ('wc' actually reports one single line because the second line does not end with a newline character):
$ cat test

jaisgossman
Offline
Beigetreten: 06/18/2018

excellent magic banana!