Skip to content
shellmap

echoPrint arguments to standard output with a trailing newline across all 5 shells

Equivalents in every shell

Bashunix
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).

Zshunix
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.

Fishunix
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).

PowerShellwindows
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.

cmd.exewindows
echo hello world

Native 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

Bash
printf "%s" "no newline"
Zsh
print -n "no newline"
Fish
echo -n "no newline"
PowerShell
[Console]::Write("no newline")
cmd.exe
<NUL set /p="no newline"

Print with interpreted escape sequences (tab, newline)

Bash
echo -e "line1\nline2\tindented"
Zsh
echo "line1\nline2\tindented"
Fish
echo -e "line1\nline2\tindented"
PowerShell
Write-Output "line1`nline2`tindented"
cmd.exe
echo line1 & echo line2

Print a variable's value (script-debug pattern)

Bash
echo "user=$USER home=$HOME"
Fish
echo "user=$USER home=$HOME"
PowerShell
echo "user=$env:USER home=$env:HOME"
cmd.exe
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.

WSL & PowerShell Core notes

pwshOn pwsh 7+ everywhere, `echo` stays aliased to `Write-Output` — pipeline-aware, type-preserving. The trailing newline is `[Environment]::NewLine` (CRLF on Windows, LF on Linux/macOS), so piping `echo "x" | sha256sum` produces DIFFERENT hashes on Windows vs Linux. For byte-stable output across platforms, use `[Console]::Out.Write("x`n")` with explicit LF.
WSLWSL bash `echo` calls the Linux builtin — identical to native Linux. The interop wrinkle: `echo "hello" | clip.exe` pipes to the Windows clipboard, and bash adds a trailing LF that Windows apps see as a stray empty line. Strip it with `printf "%s" "hello" | clip.exe`. For Win→WSL: `cmd.exe /c echo hello` from inside WSL prints `hello\r` (CRLF survives the interop boundary).

Related commands