WSL Shell Reliability
Use this skill to maximize terminal command success on Windows.
This skill does not force WSL.
It enforces a reliability-first policy:
- - pick the shell with lower failure risk,
- preserve command intent across fallback,
- never switch shells silently.
Trigger conditions
- - Any terminal execution task on Windows.
- AI-generated commands that look bash/POSIX-oriented.
- Repeated failures caused by quoting/path/shell mismatch.
One-screen decision table
| Question | If Yes | If No |
|---|
| Windows-native task/tool? | Use PowerShell/CMD | Next question |
| POSIX/bash semantics required? |
Use
WSL/bash | Next question |
| Need Linux-first parity? | Prefer
WSL/bash | Next question |
| High Windows-shell parse risk? | Prefer
WSL/bash | Next question |
| Both paths low risk? | Pick shell with fewer moving parts | N/A |
Examples:
- - Windows-native:
winget, reg, netsh, .exe/.msi, service/system ops. - POSIX-heavy:
rm -rf, export, ./script.sh, grep/sed/awk, complex pipes.
Rule priority (conflict resolution)
Apply rules in this priority order when guidance appears to conflict:
- 1. Windows-native exclusions (must use PowerShell/CMD).
- Decision table hard signals (POSIX dependence, high parse risk).
- Fallback policy + intent preservation.
- Convenience preferences (tool availability, fewer steps).
If still ambiguous, choose the shell with lower execution-failure risk.
Windows-native exclusions (prefer PowerShell/CMD)
- -
winget, scoop, INLINECODE10 - PowerShell cmdlets and registry/service/system commands
- INLINECODE11 /
.exe installer flows - Windows-targeted
msbuild/.NET packaging chains
Execution protocol
- 1. Select shell with the decision table.
- Generate syntax for that shell (do not mix grammar).
- Execute command.
- If failure is shell-related, fallback to the other shell.
- Preserve intent exactly; only translate syntax.
- State fallback explicitly.
Shell-aware generation rules
- - WSL/bash: POSIX syntax allowed.
- PowerShell: PowerShell-native quoting/escaping.
- CMD: use only when required by task/tool.
Do not run bash syntax directly in PowerShell/CMD.
WSL templates
- - INLINECODE15
- INLINECODE16
Quick translation hints (bash -> PowerShell)
- -
export FOO=bar -> INLINECODE18 - INLINECODE19 -> INLINECODE20
- INLINECODE21 -> INLINECODE22
- INLINECODE23 -> INLINECODE24
- INLINECODE25 -> INLINECODE26
Use translations only when fallback requires them.
Guardrails
- - Never silently switch shells.
- Never change command semantics when switching shells.
- Never install tools just to enforce one-shell purity.
- Prefer existing toolchain in the selected shell first.
Fallback policy
Fallback to the other shell when:
- - WSL is unavailable or unstable,
- the tool cannot be resolved in current shell,
- task is clearly Windows-native,
- command fails due to shell parsing/quoting mismatch.
When falling back, report:
- 1. what failed,
- why shell changed,
- equivalent command intent preserved.
Known limitations
- - Some enterprise environments disable WSL installation/execution.
- VPN/proxy/DNS policies may break package/network operations in one shell.
- Cross-filesystem operations can have inconsistent performance.
- Security policies may block execution scripts in PowerShell.
In these cases, prefer explicit fallback and report constraints clearly.
References
Deep technical notes and examples:
WSL Shell 可靠性
使用此技能可最大化 Windows 上终端命令的成功率。
此技能不强制使用 WSL。
它强制执行可靠性优先策略:
- - 选择故障风险更低的 shell,
- 在回退时保留命令意图,
- 绝不静默切换 shell。
触发条件
- - Windows 上的任何终端执行任务。
- 看起来面向 bash/POSIX 的 AI 生成命令。
- 由引号/路径/shell 不匹配导致的重复失败。
一屏决策表
| 问题 | 如果是 | 如果否 |
|---|
| Windows 原生任务/工具? | 使用 PowerShell/CMD | 下一个问题 |
| 需要 POSIX/bash 语义? |
使用
WSL/bash | 下一个问题 |
| 需要 Linux 优先一致性? | 优先使用
WSL/bash | 下一个问题 |
| Windows shell 解析风险高? | 优先使用
WSL/bash | 下一个问题 |
| 两种路径风险都低? | 选择移动部件更少的 shell | 不适用 |
示例:
- - Windows 原生:winget、reg、netsh、.exe/.msi、服务/系统操作。
- POSIX 密集型:rm -rf、export、./script.sh、grep/sed/awk、复杂管道。
规则优先级(冲突解决)
当指导出现冲突时,按此优先级顺序应用规则:
- 1. Windows 原生排除项(必须使用 PowerShell/CMD)。
- 决策表硬信号(POSIX 依赖、高解析风险)。
- 回退策略 + 意图保留。
- 便利性偏好(工具可用性、步骤更少)。
如果仍然不明确,选择执行失败风险更低的 shell。
Windows 原生排除项(优先使用 PowerShell/CMD)
- - winget、scoop、choco
- PowerShell cmdlet 和注册表/服务/系统命令
- .msi/.exe 安装程序流程
- 面向 Windows 的 msbuild/.NET 打包链
执行协议
- 1. 使用决策表选择 shell。
- 为该 shell 生成语法(不要混合语法)。
- 执行命令。
- 如果失败与 shell 相关,回退到另一个 shell。
- 精确保留意图;仅翻译语法。
- 明确说明回退。
Shell 感知生成规则
- - WSL/bash:允许 POSIX 语法。
- PowerShell:PowerShell 原生引号/转义。
- CMD:仅在任务/工具要求时使用。
不要在 PowerShell/CMD 中直接运行 bash 语法。
WSL 模板
- - wsl.exe -e bash --noprofile --norc -lc
- wsl.exe -e bash --noprofile --norc -lc cd /mnt// &&
快速翻译提示(bash -> PowerShell)
- - export FOO=bar -> $env:FOO = bar
- rm -rf -> Remove-Item -Recurse -Force
- cp -r a b -> Copy-Item a b -Recurse
- mv a b -> Move-Item a b
- cat file -> Get-Content file
仅在回退需要时使用翻译。
护栏
- - 绝不静默切换 shell。
- 切换 shell 时绝不更改命令语义。
- 绝不安装工具来强制单一 shell 纯净性。
- 优先使用所选 shell 中的现有工具链。
回退策略
在以下情况下回退到另一个 shell:
- - WSL 不可用或不稳定,
- 当前 shell 中无法解析工具,
- 任务明显是 Windows 原生,
- 命令因 shell 解析/引号不匹配而失败。
回退时,报告:
- 1. 什么失败了,
- 为什么更改 shell,
- 保留的等效命令意图。
已知限制
- - 某些企业环境禁用 WSL 安装/执行。
- VPN/代理/DNS 策略可能破坏一个 shell 中的包/网络操作。
- 跨文件系统操作可能性能不一致。
- 安全策略可能阻止 PowerShell 中的执行脚本。
在这些情况下,优先明确回退并清晰报告约束。
参考
深度技术笔记和示例: