echo
Quick Reference
Command Name:
echo
Category:
utilities
Platform:
linux
Basic Usage:
Common Use Cases
- 1
Text output
Display text on the console or write to files
- 2
Scripting
Use in shell scripts to output text or variables
- 3
Debugging
Print variables or debug information
- 4
Automation
Automate text output in scripts
Syntax
echo [OPTION]... [STRING]...
Options
Option | Description |
---|---|
-n | Do not output the trailing newline |
-e | Enable interpretation of backslash escapes |
-E | Disable interpretation of backslash escapes (default) |
--help | Display help information |
--version | Display version information |
Common Backslash Escapes (with -e option):
Sequence | Description |
---|---|
\n | New line |
\t | Horizontal tab |
\v | Vertical tab |
\b | Backspace |
\r | Carriage return |
\f | Form feed |
\\ | Backslash |
\a | Alert (bell) |
\0NNN | Character with octal value NNN |
\xHH | Character with hexadecimal value HH |
Examples
How to Use These Examples
The examples below show common ways to use the echo
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
Basic Examples:
echo "Hello, World!"
Display a simple text message.
echo Hello World
Echo works without quotes for simple messages (without special characters).
echo -n "No newline"
Print text without adding a trailing newline character.
echo "Current user: $USER"
Display text with variable expansion.
Advanced Examples:
echo -e "Line 1\nLine 2"
Use escape sequences to format text (enables interpretation of backslash escapes).
echo "Hello" > greeting.txt
Redirect output to a file (overwrites existing content).