1

I am a new UBUNTU browser, so that I have fave so many problems however I loved using it. I want to know that-"How to print any text or any String using terminal in Ubuntu 18.10 as Output in the terminal".

1 Answers1

0

Simplest way to print something in terminal is to either use echo or printf command.

echo foo
printf '%s\n' "foo"

For long texts - it depends. Texts of multiple lines that you construct yourself can be printed via multiple ways, one of which is just to run cat and type in text which will be output on the terminal with each line and stop that via Ctr+D ; another one is here-document structure.

$ cat  <<EOF
> This is one line
> this is another
> EOF

The << designates here-document and EOF serves as text terminator (and it can be any string so long as it's the same one). cat can be used to print text files, but in this case it prints stdin stream - one of 3 streams that each process inherits. stdin is typically connected to current terminal device, but in this case because we use here-doc it has been altered to read the temporary file which shell creates on our behalf when we use here-doc ( see also a question why this wouldn't work with echo ). Of course printing text file can be as simple as cat file.txt, but more often you want to do something with that text, and for that purpose there's multiple utilities and commands.


Of course printing any string can be a challenge. Does your terminal support printing/recognizing different locales (that is languages ?). Is the text file properly encoded ? There's plenty of considerations to take. But if you're just starting with Ubuntu, echo will be enough for sometime. Eventually, when you'll start working with multiple Linux/Unix systems you will learn that printf is better than echo for making portable scripts.

Sergiy Kolodyazhnyy
  • 105,154
  • 20
  • 279
  • 497