Questions tagged [echo]

Simple function outputting text. Exists in script languages.

echo is mainly used in batch (cmd). An example would be:

echo hello world

which prints "hello world" to the terminal.

The output by default prints directly to the command line, however, it may be piped into a following command as an input. This can be very handy and allows for interoperability between different processes/languages.

5742 questions
3405
votes
22 answers

Echo newline in Bash prints literal \n

How do I print a newline? This merely prints \n: $ echo -e "Hello,\nWorld!" Hello,\nWorld!
Sergey
  • 47,222
  • 25
  • 87
  • 129
2665
votes
33 answers

How to change the output color of echo in Linux

I am trying to print a text in the terminal using echo command. I want to print the text in a red color. How can I do that?
satheesh.droid
  • 29,947
  • 10
  • 34
  • 34
671
votes
14 answers

Multi-line string with extra space (preserved indentation)

I want to write some pre-defined texts to a file with the following: text="this is line one\n this is line two\n this is line three" echo -e $text > filename I'm expecting something like this: this is line one this is line two this is line…
cizixs
  • 12,931
  • 6
  • 48
  • 60
443
votes
10 answers

Echo tab characters in bash script

How do I echo one or more tab characters using a bash script? When I run this code res=' 'x # res = "\t\tx" echo '['$res']' # expect [\t\tx] I get this res=[ x] # that is [x]
kalyanji
  • 4,608
  • 2
  • 17
  • 6
382
votes
10 answers

How can I suppress all output from a command using Bash?

I have a Bash script that runs a program with parameters. That program outputs some status (doing this, doing that...). There isn't any option for this program to be quiet. How can I prevent the script from displaying anything? I am looking for…
6bytes
  • 5,858
  • 9
  • 37
  • 42
348
votes
4 answers

How does one output bold text in Bash?

I'm writing a Bash script that prints some text to the screen: echo "Some Text" Can I format the text? I would like to make it bold.
JamesRat
  • 3,640
  • 2
  • 16
  • 15
333
votes
37 answers

How can I repeat a character in Bash?

How could I do this with echo? perl -E 'say "=" x 100'
sid_com
  • 24,137
  • 26
  • 96
  • 187
236
votes
5 answers

How are echo and print different in PHP?

Possible Duplicate: Reference: Comparing PHP's print and echo Is there any major and fundamental difference between these two functions in PHP?
zuk1
  • 18,009
  • 21
  • 59
  • 63
201
votes
3 answers

Echo a blank (empty) line to the console from a Windows batch file

When outputting status messages to the console from a Windows batch file, I want to output blank lines to break up the output. How do I do this?
DavidRR
  • 18,291
  • 25
  • 109
  • 191
187
votes
2 answers

Reference: Comparing PHP's print and echo

What is the difference between PHP's print and echo? Stack Overflow has many questions asking about PHP's print and echo keyword usage. The purpose of this post is to provide a canonical reference question and answer about PHP's print and echo…
user187291
  • 53,363
  • 19
  • 95
  • 127
168
votes
4 answers

Why does 1...1 evaluate to 10.1?

I've just faced a little PHP snippet from 3v4l: https://3v4l.org/jmrZB echo 1...1; //10.1 And I'm afraid I have no idea how to explain its results. Why is this considered valid at all?
Gino Pane
  • 4,740
  • 5
  • 31
  • 46
148
votes
2 answers

How to use shell commands in Makefile

I'm trying to use the result of ls in other commands (e.g. echo, rsync): all: FILES = $(shell ls) echo $(FILES) But I get: make FILES = Makefile file1.tgz file2.tgz…
Adam Matan
  • 128,757
  • 147
  • 397
  • 562
139
votes
13 answers

How can I echo HTML in PHP?

I want to conditionally output HTML to generate a page, so what's the easiest way to echo multiline snippets of HTML in PHP 4+? Would I need to use a template framework like Smarty? echo '', "\n"; // I'm sure there's a better way! echo…
Robin Rodricks
  • 110,798
  • 141
  • 398
  • 607
133
votes
4 answers

Piping not working with echo command

When I run the following Bash script, I would expect it to print Hello. Instead, it prints a blank line and exits. echo 'Hello' | echo Why doesn't piping output from echo to echo work?
Elliot A.
  • 1,511
  • 2
  • 14
  • 19
126
votes
11 answers

How can I align the columns of tables in Bash?

I want to format text as a table. I tried echoing with a '\t' separator, but it was misaligned. Desired output: a very long string.......... 112232432 anotherfield a smaller string 123124343 anotherfield
user1709294
  • 1,675
  • 5
  • 18
  • 21
1
2 3
99 100