[Bug?]: Shell drops trailing spaces in parameter expansion alternate values
Open
Nobody has claimed this yet.
bug
reproducible
- Dominant language
- TypeScript
- Stars
- 8.1k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
Self-service
- I'd be willing to implement a fix
Describe the bug
When using parameter expansion with alternate values, trailing spaces are being dropped. For example:
FOO=hi && echo ${FOO:+hello }world
should output:
hello world
but the output is instead:
helloworld
To reproduce
await packageJsonAndInstall({
scripts: {
alt: "FOO=hi && echo ${FOO:+hello }world",
},
});
expect(await yarn(`run`, `alt`)).toBe("hello world\n");
Environment
System:
OS: Windows 10 10.0.22623
CPU: (12) x64 AMD Ryzen 5 2600 Six-Core Processor
Binaries:
Node: 18.15.0 - ~\AppData\Local\Temp\xfs-d5211d86\node.CMD
Yarn: 4.0.0-rc.42.dev - ~\AppData\Local\Temp\xfs-d5211d86\yarn.CMD
npm: 9.5.0 - C:\Program Files\nodejs\npm.CMD
Additional context
Running the same in a bash shell:

Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the supplied JavaScript reproduction with yarn run alt and compare its output with the expected hello world\n. Trace the shell parameter-expansion handling for alternate values, then add coverage for the trailing-space case and confirm the command preserves the space.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, shell, typescript
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100