TeX is a typesetting program, so if you “just write” something, it will go into the output DVI or PDF file. To get it to write to the terminal you need to explicitly tell it to. There are a few ways you can do that, which produce slightly different results, depending on what exactly you need. Here are a few options just to show some text:
The primitive \message{<text>}
expands <text>
and writes it to the terminal with no leading or trailing newlines, but with spaces around the message.
tex '\message{<}\message{Hello world!}\message{>} \bye'
prints:
This is TeX, Version 3.14159265 (TeX Live 2020) (preloaded format=tex)
< Hello world! >
No pages of output.
Transcript written on texput.log.
The \write<stream>{<text>}
primitive will expand <text>
and write it to the <stream>
in a new line. If the <stream>
is not open to a file, TeX will write <text>
to the terminal. The stream 17 cannot be opened to a file (except in LuaTeX), so you can use it to write to the terminal (any other stream will do, as long as it's not open). \immediate
makes the \write
be executed immediately, rather than when the next page is shipped out.
tex '\message{<}\immediate\write17{Hello world!}\message{>} \bye'
prints:
This is TeX, Version 3.14159265 (TeX Live 2020) (preloaded format=tex)
<
Hello world!
>
No pages of output.
Transcript written on texput.log.
Also, in most current implementations, writing to the stream 18 will have the <text>
be executed as a shell command (most of them require the -shell-escape
flag). Writing to -1 when running TeX on an input file will write to the .log
file (only).
The primitive \errmessage{<text>}
expands <text>
and writes it to the terminal with an error message, thus TeX prompts you for interaction after the message is printed.
tex '\errmessage{Hello world!} \bye'
prints:
This is TeX, Version 3.14159265 (TeX Live 2020) (preloaded format=tex)
! Hello world!.
<*> \errmessage{Hello world!}
\bye
?
No pages of output.
Transcript written on texput.log.
tex '\message{Hello world!} \bye'
\immediate\write16{Hello World!}\end
.