echo
Overview
echo writes its arguments to standard output, separated by spaces, usually followed by a newline. It is the everyday way to print status lines in the shell. Behavior of escapes (-e) and options differs across shells and /bin/echo — for portable formatting prefer printf.
This page stays operator-light. Shell programming depth lives in the Shell scripting parts of this book.
Syntax
echo [options] [string...]Common Options
| Option | Description |
|---|---|
-n |
No trailing newline |
-e |
Enable backslash escapes (\n, \t, \\, …) — bash builtin / some echos |
-E |
Disable escapes (bash default) |
BusyBox and non-bash echo may ignore or treat flags differently. When it matters, use printf.
Examples with Explanations
Print text
echo 'Hello'
echo Hello world
echo "User: $USER"Single quotes preserve literals; double quotes expand variables.
No newline
echo -n 'Prompt: '
# useful before read in interactive snippetsEscapes (bash)
echo -e 'line1\nline2\tcolumn'Prefer printf 'line1\nline2\tcolumn\n' for scripts you share.
Redirect / append
echo 'enabled=1' > /tmp/flags.conf
echo 'note' >> /tmp/flags.confPipe into other commands
echo 'example.com' | dig +short
echo "$TOKEN" | wc -cAvoid echo $TOKEN unquoted (word-splitting/globbing).
Show a path or command you are about to run
echo "Installing into $PREFIX"
echo "+ apt install -y curl"Common in install scripts for operator visibility.
Notes
echois often a shell builtin (type echo);/bin/echomay differ.- Arguments starting with
-can be misread as options — useprintf '%s\n' "$arg"for arbitrary data. echo *expands globs; quote when you mean a literal*.- Don’t use
echoto print binary-safe data; useprintforcat.
Additional Resources
help echo(bash)man echo