Exercise 2: Why a Stray Write-Output Breaks Your Prompt — Possible Solution ==================================================================== WHAT THE prompt FUNCTION ACTUALLY IS ------------------------------ Per this chapter, prompt is an ordinary PowerShell function with one specific, reserved name - PowerShell automatically calls it before displaying every new command line, and whatever string that function RETURNS becomes the actual prompt text shown on screen. There's nothing magic about it beyond the exact name "prompt" being what PowerShell looks for. WHY A STRAY Write-Output WOULD VISIBLY BREAK IT ------------------------------ Per Fundamentals 7's own central rule, every uncaptured line inside a function joins that function's overall return value - not just what follows an explicit return. Since prompt's entire return value becomes the literal text displayed as the prompt, a stray Write-Output "checking git..." left inside a custom prompt function wouldn't just quietly corrupt some unrelated variable the way it might in an ordinary function - it would become part of what's actually printed on screen as the prompt itself, visibly appearing as extra, unwanted text in front of (or mixed into) the intended "PS C:\path>" text, on every single command line shown. WHY THIS WORKS AS AN ANSWER ------------------------------ It correctly explains that prompt is just a specially-named function whose return value IS the displayed prompt text, and correctly applies Fundamentals 7's uncaptured-output rule to explain why a stray line there has an unusually high-visibility, immediately obvious consequence compared to an ordinary function.