Skip to content

Variable operators ${@-val}, ${arr[@]+val} on $@ and arrays broken #358

@chaliy

Description

@chaliy

Description

The variable test operators (-, +, :-, :+, =, ?) do not work correctly when applied to $@ or array subscripts ${arr[@]}.

Scope

  • ${@-minus} — outputs literal ${@-minus} or minus} instead of testing $@
  • ${@+plus} — same parsing issue
  • ${@:-minus}, ${@:+plus} — same
  • ${arr[@]-minus} — broken for empty arrays
  • ${arr[@]+plus} — broken for non-empty arrays
  • ${var-value} (without colon) — doesn't distinguish unset from empty
  • ${var=value} (without colon) — assign-if-unset not working
  • Lazy evaluation: ${x:-$((i++))} always evaluates the alternative
  • Backslash escapes in default values: ${undef-\$} should produce $

Repro

set --
echo "argv=${@-minus}"
# bashkit outputs: argv=minus} (wrong — trailing brace)
# expected: argv=minus

arr=()
echo ${arr[@]-minus}
# bashkit outputs: -minus} (wrong — literal output)
# expected: minus

echo "${undef-\$}"
# bashkit outputs: (empty) (wrong)
# expected: $

Test coverage

14 skipped tests in crates/bashkit/tests/spec_cases/bash/var-op-test.test.sh (PR #351).

Oils reference: https://github.com/oilshell/oil/blob/master/spec/var-op-test.test.sh

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions