Artificial intelligent assistant

Remove repeating string pattern from variable with POSIX parameter expansion I wanted to use 2.6.2 Parameter Expansion to remove leading characters from a string, but was surprised to find out that "Remove Largest Prefix Pattern" doesn't automatically repeat the pattern. $ x=aaaaabc $ printf %s\\n "${x##a}" aaaabc As you can see, only the first `a` has been removed. Expected output was `bc` for any of `x=bc`, `x=abc`, `x=aabc`, `x=aaabc` or `x=aaaabc`. I'm struggling to figure out how I have to write the pattern if I want to remove as many `a` as possible from the beginning of `$x`. I had no luck searching for other threads either, because many answers use bash, but I'm looking for a POSIX shell solution.

I don’t think you can do this in a generic fashion ( _i.e._ ignoring specific features of the pattern), using only POSIX shell constructs, without using a loop:


until [ "${x#a}" = "$x" ]; do x="${x#a}"; done

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 51ea8487af1e0f2aab03436c8a57fbbe