io
echo
Writes arguments to stdout separated by spaces and terminated with a newline. Behavior across systems is inconsistent (especially escape processing) — prefer printf for anything with formatting or portability requirements.
echo [-neE] [ARG ...] Common flags / operators
| Flag / Operator | Purpose |
|---|---|
| -n | Suppress the trailing newline |
| -e | Enable interpretation of backslash escapes (\n, \t) |
| -E | Explicitly disable escape interpretation (default) |
| -- | NOT supported — echo treats -- as literal text |
Examples
echo "hello $USER" Prints hello followed by the username plus a newline.
echo -n "progress..." No trailing newline — cursor stays on the same line.
echo -e "a\tb\nc" Tab between a and b, newline between b and c.
echo "$var" > file.txt Redirect echo output to a file.
Gotcha
'echo -n' works in bash but sh (dash) prints '-n' literally — use printf for portable no-newline output. Arguments beginning with dashes may be misparsed as flags; printf '%s\n' "$x" is safer.
Related
printf
Formats and prints arguments according to a C-style format string. Portable, precise, and reuses the format string if extra arguments are provided — the preferred replacement for echo when you need formatting.
read
Reads a single line from stdin (or a file descriptor) and splits it into the given variables using IFS. The workhorse for line-by-line input processing and interactive prompts.
source (.)
Executes FILE in the CURRENT shell (no subshell), so variables, functions, and aliases defined in it persist. Contrast with 'bash file' which runs in a child process — its side effects vanish when it exits.
exec
Replaces the current shell process with COMMAND (no new process is created). Without a command, applies redirections permanently to the current shell — a common way to open long-lived file descriptors.