Skip to content

[BUG] Unsupported ${var...} operators (${x//a/b}, ${x^^}, ${x:1:3}) silently expand to the wrong value #365

Open

Description

@strandly-the-agent

Checks

  • I have updated to the latest minor and patch version of Strands Shell
  • I have checked the documentation and this is not expected behavior
  • I have searched ./issues and there are no duplicates of my issue

Binding

Rust

Strands Shell Version

main at dbb6189 (crate version is the 0.0.0 placeholder)

Language Runtime Version

Rust 1.100.0

Operating System

Debian 12 (aarch64)

Installation Method

built from source

Steps to Reproduce

Save as p.sh and run strands-shell -c "$(cat p.sh)":

x=a-b; echo "1 ${x//a/_}"
x=a-b; echo "2 ${x/a/_}"
x=hello; echo "3 ${x:1:3}"
x=hello; echo "4 ${x^^}"
x=HELLO; echo "5 ${x,,}"
x=hello; echo "6 ${x^}"
x=hello; echo "7 ${x:1}"
x=hello; echo "8 ${x/#he/HE}"
x='my file(1).txt'; echo "9 ${x//[^a-zA-Z0-9.]/_}"

Expected Behavior

Either bash's output, or an error that names the unsupported expansion (the way arrays report arrays are not supported). bash 5.2.15 prints:

1 _-b
2 _-b
3 ell
4 HELLO
5 hello
6 Hello
7 ello
8 HEllo
9 my_file_1_.txt

Actual Behavior

Exit status 0, nothing on stderr, and the operator is dropped. The substring forms also leave stray text behind:

1 a-b
2 a-b
3 hello1:3}
4 hello
5 HELLO
6 hello
7 hello1}
8 hello
9 my file(1).txt

A script that sanitises a name with ${x//[^a-zA-Z0-9.]/_} or lowercases with ${x,,} carries on with the unchanged value and no sign that anything went wrong.

Additional Context

Found while reviewing #351; it is unrelated to that change and behaves the same with and without it.

In src/parser.rs, after the variable name is read:

  • The fallback arm at lines 574-584 handles any operator it doesn't know (/, ^, ,, @). It skips to the closing } and returns WordPart::Var(name).
  • The : arm at lines 531-543 returns WordPart::Var(name) for a colon that isn't followed by -, =, ? or +, without consuming the rest. That is why ${x:1:3} prints hello1:3}.

Possible Solution

Short term: report unsupported operators as an error instead of dropping them. Longer term: implement ${var/pat/rep}, ${var//pat/rep}, ${var:offset:length} and the case-conversion forms.

Related Issues

#207 (bash-isms agents write by default; these forms aren't on its list)

Activity

  1. added
    bug
    on Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    Fields

    Language

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions