echo — Print arguments to standard output with a trailing newline across all 5 shells
Equivalents in every shell
echo "hello world"Builtin in bash 4+; the standalone `/bin/echo` (or `/usr/bin/echo`) differs subtly. Bash builtin does NOT interpret backslash escapes by default — pass `-e` to enable `\n`, `\t`, `\\`. Pass `-n` to suppress the trailing newline. The POSIX-safe replacement is `printf` (see gotcha 1).
echo "hello world"Behaviour close to bash, but zsh's builtin defaults to interpreting `\n`/`\t` escapes — the opposite of bash. Use `setopt BSD_ECHO` to match bash behaviour, or always reach for `print -r --` for unambiguous output.
echo "hello world"Fish `echo` is a builtin. Like bash, no escape interpretation by default — use `echo -e` for `\n`/`\t`. Fish-specific: `echo -s` joins arguments WITHOUT spaces (vs default space-separated).
echo "hello world"`echo` is an alias for `Write-Output`. Adds the platform newline (CRLF on Windows pwsh, LF on Linux/macOS pwsh) and passes the string DOWN the pipeline as a `[string]` object — not raw bytes. Use `Write-Host` for direct console output that bypasses the pipeline, or `[Console]::Write("...")` for byte-exact stdout with no trailing newline.
echo hello worldNative cmd builtin. Quotes are NOT stripped — `echo "hello"` outputs literal `"hello"` (with quotes). Special case: `echo.` (with the dot) prints a blank line — bare `echo` toggles echo-state display. Use `echo|set/p=text` to print WITHOUT a trailing newline (the canonical cmd hack).
Worked examples
Print without a trailing newline
printf "%s" "no newline"print -n "no newline"echo -n "no newline"[Console]::Write("no newline")<NUL set /p="no newline"Print with interpreted escape sequences (tab, newline)
echo -e "line1\nline2\tindented"echo "line1\nline2\tindented"echo -e "line1\nline2\tindented"Write-Output "line1`nline2`tindented"echo line1 & echo line2Print a variable's value (script-debug pattern)
echo "user=$USER home=$HOME"echo "user=$USER home=$HOME"echo "user=$env:USER home=$env:HOME"echo user=%USERNAME% home=%USERPROFILE%Gotchas
- `echo -n` (suppress newline) is NOT POSIX — bash builtin honours it, but `/bin/echo` on some systems (notably Solaris' standard `/bin/echo`) prints the literal `-n`. The portable replacement is `printf "%s" "$x"`. For scripts shipping to alpine / busybox / BSD, prefer `printf` over `echo -n`.
- bash and fish do NOT interpret `\n`/`\t` by default; zsh DOES. Same script in bash prints `\nlit` literally but in zsh prints a newline. Either pass `-e` explicitly (bash/fish) or use `printf "%b\n" "..."` for cross-shell consistency.
- PowerShell `echo "$x"` passes a `[string]` down the pipeline, NOT raw bytes — `echo "hello" | Out-File f.txt` writes `hello\r\n` plus a BOM (default UTF-16 LE on Windows pwsh 5.1, UTF-8 NoBOM on pwsh 6+). For byte-exact stdout that downstream Unix tools can parse, use `[Console]::Write("$x")` or `Write-Host` with `-NoNewline`.
- cmd `echo "hello"` outputs literal `"hello"` (quotes are part of the argument); bash/zsh/fish/powershell strip the quotes. Cross-shell scripts that go through cmd need to strip quotes manually: `echo %~1` (the `~` modifier strips surrounding quotes from `%1`).
- Colored output: there's no `--color` flag on `echo` anywhere. Bash/zsh/fish use ANSI escapes (`echo -e "\033[32mgreen\033[0m"`); pwsh uses `$PSStyle.Foreground.Green` (pwsh 7.2+) or `Write-Host -ForegroundColor Green`; cmd needs Windows 10+ for ANSI passthrough + a `chcp 65001` to keep UTF-8 intact.