Repository navigation
Apply the options on a script's #! line - #9
Merged
Merged
Conversation
ExpectedArgument
force-pushed
the
fix-shebang-options
branch
from
November 6, 2026 19:26
9182933 to
7e8f727
Compare
classify_file recognised a shell interpreter on the #! line but dropped what followed it, so #!/bin/bash -e, -u, -x and env -S bash -e had no effect on scripts run in-process, and the spawned path didn't pass them either. They are now kept on Resolved and applied to the child shell with the command-line parser: as on Linux, the rest of the line is one argument, split into words after env. parse_cli gains a quiet mode and the set/shopt part of real_main moves into apply_options, which both use. If bash would report something (an invalid option, --version), the script runs as a separate gash process, which does. Fixes hex2f#3. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ExpectedArgument
force-pushed
the
fix-shebang-options
branch
from
November 6, 2026 19:36
7e8f727 to
89263d5
Compare
hex2f
reviewed
Nov 6, 2026
hex2f
left a comment
Owner
There was a problem hiding this comment.
Thanks for this, and for the rebase and the test rename. It fixes #3. I found nothing to change.
The rebased branch passes cargo test: all 66 compat scripts, including the new 071_shebang_options. Moving set/shopt handling into apply_options, so that #! options go through the same parser as the command line, is a nice way to get bash's behaviour for errors like -o pipefail given as one argument.
Looks good to merge.
hex2f
approved these changes
Nov 6, 2026
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.
Fixes #3.
classify_filerecognised a shell interpreter on the#!line but dropped what followed it, so#!/bin/bash -e,-u,-xandenv -S bash -ehad no effect on scripts run in-process, and the spawned path (GASH_NO_INPROC) didn't pass them on either.Resolved(opts) and applied to the child shell with the command-line parser, so they behave exactly as on the command line.parse_cligains areportflag for a quiet mode, and theset/shoptpart ofreal_mainmoves intoapply_options, which both now use.-e,-eu,+eand-xwork, and-e -uis an error, as with bash. Afterenv, with or without-S, it is split into words.--version, ...), the script runs as a separate gash process, which reports it the way bash does, on the script's own stdout and stderr.Tests
071_shebang_options.sh, with expected output from Git Bash 5.3.15 viaregen_expected.ps1. It covers-e,-u,-eu,env -S bash -e,#!/bin/sh -e,+e,set +eafter-e,-o pipefailas one argument (an error in bash),-uwith arguments, and-x. It fails with v0.1.0 and passes with this branch.cargo testpasses: unit tests, 66/66 compat scripts andmsys_tmp.