Skip to content

feat: bash compatibility — compound arrays, grep -f, awk getline, jq env#238

Merged
chaliy merged 6 commits intomainfrom
claude/bashkit-bash-compatibility-BsDKD
Feb 24, 2026
Merged

feat: bash compatibility — compound arrays, grep -f, awk getline, jq env#238
chaliy merged 6 commits intomainfrom
claude/bashkit-bash-compatibility-BsDKD

Conversation

@chaliy
Copy link
Contributor

@chaliy chaliy commented Feb 24, 2026

Summary

  • Compound associative array init: declare -A m=([k]=v) now tokenized as single word; lexer peeks for [ after =( to distinguish from indexed arrays
  • grep -f pattern-only mode: fix parse requiring positional pattern when -f is specified; unskip grep -r and grep -f tests with proper VFS file setup
  • AWK getline: implement getline statement with index-based iteration; fix ORS and missing-field test expectations
  • JQ env access: expose bashkit shell vars to process env so jaq's env builtin works; RAII drop guard for cleanup on all return paths
  • String ops, read -r, heredocs (from prior commit on branch): prefix/suffix replace, heredoc tests, read builtin backslash handling

Test plan

  • cargo clippy --all-targets --all-features -- -D warnings clean
  • cargo test --all-features — all pass (69 lib + 101 doc)
  • cargo test --test spec_tests — 13 suites green
  • 9 previously-skipped tests unskipped
  • ~12 new spec + unit tests added (positive and negative)

- Implement ${s/#pat/repl} prefix-anchored and ${s/%pat/repl}
  suffix-anchored pattern replacement
- Implement ${var:?"msg"} error expansion with exit code 1
- Handle \/ escape in pattern replacement parsing
- Add read builtin -r flag (raw mode, no backslash interpretation)
  and -p flag parsing
- Add 31 new bash spec tests:
  - heredoc.test.sh (9): variable expansion, quoted delimiters,
    file redirects, command/arithmetic substitution
  - string-ops.test.sh (15): prefix/suffix replace, :?, :+,
    case conversion, indirect expansion, negative substring
  - read-builtin.test.sh (7): IFS splitting, -r flag, here-string
- Bash spec tests: 741 total, 735 pass, 6 skip (100% pass rate)
- Bash comparison: 668/668 match real bash (100%)

https://claude.ai/code/session_012rzB3FRw7yoQWCG1mxyW7J
Lexer now keeps `var=([key]=val ...)` as a single token so the
interpreter's existing compound-assignment handler receives the full
expression.  Only activates when the first non-whitespace char after
`=(` is `[`, preserving the existing token-by-token path for indexed
arrays like `arr=("hello world")`.

Unskips assoc_declare_inline spec test; adds 3 more compound-init
test cases and 2 lexer unit tests.

https://claude.ai/code/session_012rzB3FRw7yoQWCG1mxyW7J
- grep -f without a positional pattern now works (was erroring with
  "missing pattern" because parse required a positional even when -f
  was set)
- Rewrote grep_recursive spec test to actually create files and verify
  recursive directory traversal
- Rewrote grep_pattern_file spec test to create pattern file first
- Added negative tests: grep_recursive_no_match, grep_pattern_file_no_match

https://claude.ai/code/session_012rzB3FRw7yoQWCG1mxyW7J
- Implement `getline` statement: reads next input record into $0,
  updates NR/NF/FNR. Refactored main loop to index-based iteration
  so getline can advance the line pointer.
- Unskip awk_ors: workaround spec runner trailing newline by appending
  `; echo` (ORS itself was already implemented correctly)
- Unskip awk_missing_field: rewrote test to verify empty string via
  conditional instead of relying on empty expected output
- Unskip awk_getline: basic getline now works
- Add 3 new getline spec tests (updates_dollar_zero, at_eof, three_lines)
- Add 3 new getline unit tests (basic, updates_fields, at_eof)

https://claude.ai/code/session_012rzB3FRw7yoQWCG1mxyW7J
jaq's built-in `env` function reads from std::env::vars() which
doesn't see bashkit's virtual environment. Fix: temporarily expose
ctx.env and ctx.variables to the process environment before running
jaq, with an RAII drop guard for cleanup on all return paths.

- Unskip jq_env spec test
- Add jq_env_missing and jq_env_in_pipeline spec tests
- Add test_jq_env_access and test_jq_env_missing_var unit tests

https://claude.ai/code/session_012rzB3FRw7yoQWCG1mxyW7J
Replace per-value empty inputs iterator with a shared RcIter over
all parsed JSON values.  Main loop and filter's input/inputs functions
consume from the same source, matching real jq behavior.

- Unskip jq_input and jq_inputs spec tests
- Add jq_input_with_dot, jq_inputs_empty spec tests
- Add 3 unit tests (input_reads_next, inputs_collects_remaining,
  inputs_single_value)

https://claude.ai/code/session_012rzB3FRw7yoQWCG1mxyW7J
@chaliy chaliy merged commit 53b8477 into main Feb 24, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants