Skip to content
shellmap

write-hostPrint colored text to the terminal — bypasses the pipeline across all 5 shells

Equivalents in every shell

Bashunix
echo "hello"

Builtin. For coloured output, use ANSI escapes directly: `echo -e "\033[31mred\033[0m"`, or via `tput setaf 1` (terminfo). Output ALWAYS goes to stdout — it can be piped, captured, or redirected.

Zshunix
echo "hello"

Builtin. `print -P "%F{red}red%f"` uses zsh prompt-expansion codes for colour without raw ANSI. Like bash, output is always stdout — there is no UI-only sink.

Fishunix
set_color red; echo "hello"; set_color normal

`set_color` is the fish-native helper for ANSI escapes; accepts colour names (`red`, `brblue`, `--bold`). `echo` itself is the same builtin used for general output.

PowerShellwindows
Write-Host "hello" -ForegroundColor Red

Writes to the HOST UI (Information stream 6 in pwsh 5+). Cannot be piped, captured by `=`, or redirected with `>`. Supports `-ForegroundColor` / `-BackgroundColor` (named `[ConsoleColor]`), `-NoNewline`, and `-Separator`.

cmd.exewindows
echo hello

Built-in. cmd has NO native per-line coloured output — `color 0C` recolours the WHOLE console (background 0, foreground C=red) until reset. For inline colour, shell out: `powershell -Command "Write-Host hello -ForegroundColor Red"`.

Worked examples

Print a coloured banner

Bash
echo -e "\033[1;32mDone\033[0m"
Fish
set_color green --bold; echo Done; set_color normal
PowerShell
Write-Host "Done" -ForegroundColor Green

Print on the same line (no newline)

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

Show progress without polluting the success pipeline

Bash
echo "step 1" >&2
PowerShell
Write-Host "step 1"

Gotchas

  • `Write-Host` is a HOST-UI write — it bypasses the success stream entirely. `$x = Write-Host 'hi'` makes `$x = $null` and the text prints directly. For chainable / capturable output use `Write-Output` instead; for diagnostic streams use `Write-Verbose` / `Write-Information`.
  • It CANNOT be redirected with `>` or `2>` — only with the stream-6 redirect: `Write-Host 'hi' 6>file.txt` (pwsh 5+). PowerShell 4.x and earlier had no way at all to capture `Write-Host` output, which is why long-lived scripts traditionally avoid it for anything users might want to log.
  • `-ForegroundColor` / `-BackgroundColor` accept the `[ConsoleColor]` enum names (`Red`, `DarkGreen`, `Yellow`, etc.) — case-insensitive but typo-intolerant: `Write-Host -ForegroundColor red2` throws. For 24-bit truecolour on pwsh 7.2+, use `$PSStyle`: `Write-Host "$($PSStyle.Foreground.FromRgb(255,128,0))hi$($PSStyle.Reset)"`.
  • Multiple positional arguments are joined by `-Separator` (default: single space): `Write-Host 1 2 3` prints `1 2 3`. Arrays are flattened the same way — to print structured data one-per-line, loop with `ForEach-Object { Write-Host $_ }`.
  • `Start-Transcript` DOES capture `Write-Host` output to the transcript file (via the Information stream on pwsh 5+) even though it bypasses normal redirection. Scripts that print secrets with `Write-Host` will leak them into transcripts — use `Write-Verbose` (gated by `$VerbosePreference`) for sensitive diagnostic output.

WSL & PowerShell Core notes

pwsh`Write-Host` is identical on every pwsh platform — the named `[ConsoleColor]` palette maps to the same ANSI sequences on Linux/macOS. Truecolour via `$PSStyle` (pwsh 7.2+) works in any ANSI-aware terminal (Windows Terminal, iTerm2, GNOME Terminal, kitty). For scripts that must run on Windows PowerShell 5.1, stick to the 16-colour named palette.
WSLInside WSL bash, use raw ANSI escapes or `tput setaf` for colour — `Write-Host` requires a pwsh host. To call it from WSL: `pwsh.exe -c "Write-Host hi -ForegroundColor Red"` invokes Windows-side pwsh via interop. The colour escapes round-trip cleanly through the shared Windows Terminal pane.

Related commands