Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions crates/bashkit/src/builtins/flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ fn loop_control(name: &str, ctx: &Context<'_>, make: fn(u32) -> ControlFlow) ->
0,
);
}
if let Some(arg) = ctx.args.first()
&& arg.trim().parse::<i64>().is_ok()
&& ctx.args.len() > 1
{
// Like `exit`: bash discards the rest of the line.
let mut result = ExecResult::err(format!("bash: {name}: too many arguments\n"), 1);
result.control_flow = ControlFlow::Abort;
return result;
}
let levels = match ctx.args.first() {
None => 1,
Some(arg) => match arg.trim().parse::<i64>() {
Expand Down
17 changes: 15 additions & 2 deletions crates/bashkit/src/interpreter/brace_expansion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ impl Interpreter {
// No valid brace pattern found
let (start, end) = match (brace_start, brace_end) {
(Some(s), Some(e)) => (s, e),
// An unclosed `{` is literal; a later group may still close
// (`{{a,b}` -> `{a {b`).
(Some(open), None) => {
return self.expand_after_literal_brace(
&chars,
open,
count,
bytes,
max,
recursion_depth,
);
}
_ => return vec![s.to_string()],
};

Expand Down Expand Up @@ -267,7 +279,8 @@ impl Interpreter {
// Parse optional step (default: 1 or -1 based on direction)
let step: i64 = if parts.len() == 3 {
match parts[2].parse::<i64>() {
Ok(0) => return None, // step=0 is invalid
// bash treats a zero step as 1.
Ok(0) => 1,
Ok(s) => s,
Err(_) => return None,
}
Expand Down Expand Up @@ -329,7 +342,7 @@ impl Interpreter {
if start_char.is_ascii_alphabetic() && end_char.is_ascii_alphabetic() {
let step: i64 = if parts.len() == 3 {
match parts[2].parse::<i64>() {
Ok(0) => return None,
Ok(0) => 1,
Ok(s) => s,
Err(_) => return None,
}
Expand Down
Loading
Loading