Repository navigation
shell: write a literal line into a PowerShell profile - #23996
Merged
Merged
Conversation
`>>` binds to the pipeline, so `$env:X='y' >> profile` redirects the assignment's value instead of appending the line: the variable is left null and the profile receives a bare `y`, which errors on next start. The PATH variant empties `$env:PATH` and appends the expanded path. Emit the line as a quoted string, as every other branch does with echo.
7 of 8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
brew benchmarkresults.brewcommands to reproduce the bug?brew lgtm(style, typechecking and tests) locally?Utils::Shell.set_variable_in_profileandprepend_path_in_profilebuild a command the user is told to paste. Every branch wraps the profile line inecho '...'except the PowerShell one, which redirects the assignment itself:>>binds to the pipeline, so PowerShell parses those as$env:X = ('y' >> profile). The assignment gets the redirection's result, which is null, and the profile receives the bare value.Against PowerShell 7.4.6 on macOS, running what
brewcurrently prints:The PATH one is worse, because it also blanks
$env:PATHin the running session and writes the expanded path as a bare line. Sourcing the profile afterwards gives:So a PowerShell user following
brew's own advice ends up with a profile that errors on every start and never sets the variable.To reproduce from
brew: withSHELL=/usr/bin/pwsh,brew linkon a keg-only formula prints theprepend_path_in_profilecommand, andbrew --env/brew doctorpaths print theset_variable_in_profileone.The fix emits the line as a quoted string, matching what the other branches do with
echo.pwsh_quotesits alongsidesh_quoteandcsh_quote; PowerShell single-quoted strings only treat'specially (doubled), so$,"and backticks need nothing. After the fix, the same session:Not touched:
Utils::Shell.export_valuestill has nopwshbranch and returnsnilthere, sobrew --env --shell=pwshand the caveats blocks print nothing for PowerShell users. That is a missing feature rather than a wrong command, andcmd/shellenv.shalready handlespwshseparately, so it looked like its own change.brew lgtmis green, and reverting onlyutils/shell.rbfails exactly the three new examples.AI disclosure: the diff, the tests and the PowerShell verification above were produced by Claude Opus 5 in Claude Code on my machine. I have not yet read the diff line by line myself, so the last box stays unticked until I have; I answer review comments myself, and no commit here is attributed to an AI.