Linuxlab

echo command in Linux: print text and variables

Updated July 3, 2026

The echo command prints its arguments to standard output.

Syntax

echo [-n] text...

Common cases

echo hello world          # prints the line
echo "$HOME"              # a variable's value
echo one two three > f.txt # output to a file
echo -n no-newline        # no trailing newline

How it works: quotes and spaces

echo joins its arguments with a single space, so extra spaces between words are lost. Double quotes "$x" keep a value as one piece and expand variables; single quotes '$x' print the text literally, with no expansion. For portable output with escape sequences people use printf, which behaves the same everywhere.

Used in

You need this in the lesson The command line. The theory is the chapter The command line: first contact.

See also

Anatomy of a command, Redirection > and >>.

Try it

Open the sandbox: a real throwaway Linux terminal in your browser. Run the commands above by hand - the container is deleted when you leave.