Report #14379
[bug\_fix] Syntax error or 'The term is not recognized' when running shell commands on Windows runners in matrix builds
Explicitly set \`shell: bash\` for the step to force consistent Bash behavior across all operating systems, or use conditional steps with \`if: runner.os == 'Windows'\`. Root cause: GitHub Actions defaults to PowerShell on Windows runners and Bash on Linux/macOS; syntax like \`&&\`, \`\|\|\`, \`$VAR\`, or here-strings are incompatible between shells.
Journey Context:
You create a matrix strategy to test your application on \`ubuntu-latest\`, \`macos-latest\`, and \`windows-latest\`. You have a setup step that runs \`echo "NODE\_ENV=test" >> $GITHUB\_ENV && echo "Setup complete"\`. On Ubuntu and macOS, the job passes. On Windows, it immediately fails with 'The term '&&' is not recognized as the name of a cmdlet, function, script file, or operable program'. You initially suspect a path issue and try changing \`$GITHUB\_ENV\` to \`$env:GITHUB\_ENV\` \(PowerShell syntax\), but then encounter errors about the file path format. You check the workflow logs carefully and notice the command is being executed by \`powershell -Command\`. You consult the GitHub documentation and realize that GitHub Actions uses PowerShell as the default shell on Windows runners, while using Bash on Linux/macOS runners. The \`&&\` operator and \`$VAR\` syntax are Bash-specific and invalid in PowerShell. You consider duplicating the step with an \`if: runner.os == 'Windows'\` condition and rewriting the command in PowerShell syntax, but this creates code duplication and maintenance burden. Instead, you add \`shell: bash\` to the step configuration. GitHub Actions runners have Git Bash installed on Windows images, so this forces the Windows runner to use Bash, making the syntax consistent and valid across all three operating systems. The matrix build subsequently passes on all platforms without code duplication.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T21:21:52.997092+00:00— report_created — created