Skip to content
shellmap

write-outputSend objects down the pipeline — echo for objects across all 5 shells

Equivalents in every shell

Bashunix
echo "hello"

Builtin. Adds a trailing newline by default; pass `-n` to suppress. `printf` is the POSIX-portable alternative when you need format strings or no implicit newline (`printf "%s" "$x"`).

Zshunix
echo "hello"

Builtin. Same `-n` flag as bash. Zsh also has `print` (`-l` for newline-separated array, `-r` for raw / no interpretation) which is more flexible than `echo` for complex output.

Fishunix
echo "hello"

Builtin. Fish `echo` does NOT interpret backslash escapes by default (a deliberate departure from bash) — pass `-e` to enable, or use `printf` for portable escape handling.

PowerShellwindows
Write-Output "hello"

Aliased as `echo` and `write`. Emits objects to the SUCCESS pipeline stream — the value can be piped to the next cmdlet, captured by `=`, or assigned. `Write-Host` is different: it bypasses the pipeline and writes directly to the host UI (you cannot pipe or capture it).

cmd.exewindows
echo hello

Built-in. cmd `echo` does NOT need quotes around arguments — quotes are emitted as part of the output. `echo.` prints an empty line; `echo off` / `echo on` control batch-file echoing.

Worked examples

Print a literal string

Bash
echo "hello world"
Fish
echo hello world
PowerShell
Write-Output "hello world"
cmd.exe
echo hello world

Emit a value into a pipeline for further processing

Bash
echo 42 | bc
PowerShell
Write-Output 1, 2, 3 | Measure-Object -Sum

Print without a trailing newline

Bash
echo -n "no newline"
Fish
echo -n "no newline"
PowerShell
Write-Host "no newline" -NoNewline
cmd.exe
set /p "=no newline" <nul

Gotchas

  • `Write-Output` writes to the SUCCESS stream (stream 1) — it can be piped, captured with `$x = Write-Output ...`, or redirected with `>`. `Write-Host` writes to the HOST UI (stream 6 in pwsh 5+) — it cannot be piped or captured by `=` (`$x = Write-Host 'hi'` makes `$x = $null` and prints `hi` directly). Use `Write-Output` when you want a chainable value; reserve `Write-Host` for ANSI-coloured banners aimed at the user.
  • Multiple arguments are passed as an ARRAY: `Write-Output 1 2 3` emits THREE objects, not the string `'1 2 3'`. To get a single string, join first: `Write-Output ('hello world')` or `Write-Output "$x $y"`.
  • Implicit output: the LAST line of a function body or script that produces a value (without `Write-Output`) is implicitly returned via the pipeline. `function f { 42 }` and `function f { Write-Output 42 }` behave identically — but the implicit form trips bash users who expect `return 42` semantics.
  • `echo` is a pwsh alias for `Write-Output` on Windows. On Linux/macOS pwsh hosts the alias is ALSO `Write-Output`, but the system `/bin/echo` is on PATH — if you specifically want the Unix tool (with its `-e` / `-n` quirks), use `& /bin/echo` to bypass the alias.
  • `Write-Output -NoEnumerate` is needed when emitting a single array as ONE object. Without it, `Write-Output @(1,2,3)` unrolls to three pipeline items; with it, the receiver sees one `[object[]]` of length 3. This bites scripts that round-trip arrays through a function.

WSL & PowerShell Core notes

pwsh`Write-Output` is identical on every pwsh platform. The `echo` and `write` aliases are present on all of them — but on Linux/macOS pwsh, `& echo` (with the leading invoke operator forcing external resolution) reaches `/bin/echo` instead, which lets you opt into Unix `-e`/`-n` behaviour when porting bash scripts. For cross-platform scripts, always spell `Write-Output` to avoid the alias-vs-binary ambiguity.
WSLInside WSL bash, `echo` is the bash builtin. To call pwsh `Write-Output` from WSL, use `pwsh.exe -c "Write-Output 'hello'"` (calls Windows-side pwsh via interop) or install pwsh inside the WSL distro. Conversely, calling bash `echo` from Windows-side pwsh: `wsl.exe -e bash -c 'echo hello'`. Output streams cross the boundary cleanly — stdout from one side becomes stdin to the other.

Related commands