write-host — Print colored text to the terminal — bypasses the pipeline across all 5 shells
Equivalents in every shell
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.
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.
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.
Write-Host "hello" -ForegroundColor RedWrites 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`.
echo helloBuilt-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
echo -e "\033[1;32mDone\033[0m"set_color green --bold; echo Done; set_color normalWrite-Host "Done" -ForegroundColor GreenPrint on the same line (no newline)
echo -n "."Write-Host "." -NoNewline<nul set /p "=."Show progress without polluting the success pipeline
echo "step 1" >&2Write-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.