The echo command in Linux prints text or variable values to standard output. It’s commonly used in Bash scripts to display messages, expand environment variables, control newlines with options like -n and -e, and redirect output to files. Typical use cases include logging, configuration automation, and quick checks in the terminal.
Whether you’re new to shell scripting or optimizing production servers, the echo command in Linux is one of the first tools you’ll use. In this guide, I’ll explain echo with practical examples, options, and best practices from real world hosting and DevOps environments, so you can script confidently and portably.
What is the echo Command in Linux?
echo is a shell built in (in Bash, Zsh, etc.) that writes its arguments to standard output (stdout).

There’s often also an external /bin/echo. While both output text, behavior can vary across shells especially with escape sequences and option handling so portability matters.
Basic syntax:
echo [options] [string ...]Common options:
- -n: Do not output the trailing newline
- -e: Enable interpretation of backslash escapes (e.g., n, t)
- -E: Disable interpretation of backslash escapes (default in many shells)
Important portability note: POSIX marks some echo behaviors (like -e escapes) as implementation defined. For scripts that must be portable and predictable, prefer printf for complex formatting.
Basic echo Examples
Print simple text
echo Hello, World!Print environment variables
echo "$HOME"
echo "User: $USER, Shell: $SHELL"Use double quotes to expand variables and preserve spaces; single quotes prevent expansion.
Command substitution
echo "Today is: $(date +%F)"
echo "Kernel: $(uname -r)"Handle spaces and special characters
echo "Path with spaces: /var/www/My Site"
echo "Dollar sign: $, Backslash: \, Asterisk literal: *"Newlines, Tabs, and Escapes with -e
With -e, echo interprets backslash escapes. Common sequences include:
- n: newline
- t: horizontal tab
- r: carriage return
- a: alert (bell)
- b: backspace
- v: vertical tab
- xHH: byte with hex value HH
