Repository navigation
Make env.sh compatible with POSIX sh - #618
Open
RaphaelFakhri wants to merge 1 commit into
Open
RaphaelFakhri wants to merge 1 commit into
RaphaelFakhri wants to merge 1 commit into
Conversation
The generated env.sh used the bash-only ${PATH//...} and ${PATH/#...}
expansions. It is sourced from ~/.profile, which POSIX sh login shells
such as dash also read, and dash fails with "Bad substitution" and exits.
The substring removal also corrupted PATH entries that start with the
bin directory path.
Remove the bin directory from PATH with POSIX parameter expansions that
match whole entries only, and upgrade env.sh files written in the
previous format.
RaphaelFakhri
requested review from
cmcgee1024,
etcwilde,
justice-adams-apple and
shahmishal
as code owners
November 4, 2026 07:29
This branch has not been deployed
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.
Motivation
swiftly initadds. env.shto~/.profilefor bash users without~/.bash_profileor~/.bash_login(the Debian and Ubuntu default) and for shells other than bash, zsh, and fish. POSIXshlogin shells also read~/.profile. On Debian and Ubuntu,/bin/shis dash, which doesn't support the${PATH//...}and${PATH/#...}expansions thatenv.shuses. dash reportsBad substitutionand exits, so the rest of~/.profileand the calling script don't run:The substring removal also isn't anchored on both sides, so a
PATHentry such as$SWIFTLY_BIN_DIR2turns into2.Changes
env.shwith POSIX parameter expansions that remove only wholePATHentries equal toSWIFTLY_BIN_DIR, then prepend it. The temporary variable is unset afterwards.env.shformat during theswiftly initupgrade path, so existing installs get the fixed file.initEnvShIsPOSIXCompatible, which sources the generatedenv.shwith/bin/shand checks the exit status and resultingPATH.initUpgradeand update the expected output.Testing
swift test --filter InitTestson Debian 13 (/bin/shis dash), Swift 6.4.0: fails without the source change (initEnvShIsPOSIXCompatibleand threeinitUpgradecases) and passes with it (9 tests).shforPATHvalues with the bin directory at the start, middle, and end, repeated, absent, alone, empty, and with a similarly prefixed entry.swift run swiftformat --lint --dryrunreports no changes.Fixes #617