Repository navigation
Pass script arguments like Bash: $0, $@, "$@", ${1:-x}, and the set -x trace - #294
Merged
Merged
Conversation
Rust 1.99 rejects a trailing semicolon in a macro used in expression position (semicolon_in_expressions_from_non_local_macros), which miette's bail! has. Use bail! as a statement instead. Also replace a drain().collect() into the same collection type with std::mem::take.
The trace was written to stdout, so it ended up in the output of command substitutions and pipes. Write it to stderr, as Bash does. Fixes prefix-dev#293
$@ and $# were computed from the shell's own command line, including the shell binary, its options and the script path, and $0 and $* were not set. Set $0 to the script path (or the name the shell was invoked as) and $@, $* and $# from the script arguments, as Bash does. Fixes prefix-dev#290
Only names were accepted inside ${...}, so ${1}, ${1:-default}, ${10},
${@} and ${*} were output literally. Accept positional parameters
there, with modifiers for ${N}. Modifiers on ${@} and ${*}, such as the
${@:2} slice, are still not supported.
Fixes prefix-dev#292
"$@" expanded to a single word with all positional parameters joined by spaces, so arguments could not be forwarded intact. Expand it to one word per parameter, as Bash does: text around it joins the first and last parameters, and with no parameters "$@" gives no word at all. Unquoted $@ also gives one word per (non-empty) parameter. shift now updates $@ and $* as well. Fixes prefix-dev#291
certik
force-pushed
the
fix/script-args
branch
from
October 17, 2026 21:09
ccdcc9d to
c549a19
Compare
Closed
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.
Summary
Make scripts receive and forward their arguments like Bash. These are the fixes needed to run LFortran's build scripts, which take a build directory and forward CMake arguments, with
shellon every platform.$0,$@,$*and$#come from the script arguments, not from the shell's own command line.$0is the script path."$@"expands to one word per positional parameter. Text around it joins the first and last parameters ("pre$@post"), and with no parameters it gives no word at all. Unquoted$@gives one word per non-empty parameter.shiftnow also updates$@and$*.${1},${10},${1:-default},${@}and${*}are expanded instead of printed literally. Modifiers on${@}/${*}, such as the${@:2}slice, are still not supported.set -xtrace goes to stderr, so it no longer ends up in$(...)output.Fixes #290, fixes #291, fixes #292, fixes #293.
The first commit fixes the lints that the current stable Rust (1.99) reports in existing code, which made the
clippyjob fail: miette'sbail!used in expression position (semicolon_in_expressions_from_non_local_macros) and adrain().collect()into the same collection type. It doesn't change behavior.Each fix is a separate commit with its own tests.
crates/shell/tests/script_args.rsruns theshellbinary on scripts, which coversmain.rs, where the script arguments are set up.Validation
cargo fmt -- --checkcargo clippy --all-targets --workspace -- -D warningsandcargo test --workspace --all-targets, on every commit, with Rust 1.99.1 (as in CI) and 1.95; the new tests fail without their fix"$@"gives the same words for no arguments, an empty argument, arguments with spaces,"pre$@post",x"$@"yand"$@$@"Unquoted expansions are still not split on whitespace (
for w in $v, unquoted$*), as before. That behaviour is unchanged here.