0

How do we remove from first till a certain string in array just like that of in plain string by ${..#..} e.g. ${s#abc}

$ s=(e u i o foo a)
$ t=(${s[@]#*foo})
$ echo "${t[@]}"

e u i o a

instead of expected:

a

How to correcly do it so solve such need ?

1

If switching to zsh is an option, you could do it as:

s[(r)foo,-1]=()

Where r is the reverse subscripting flag which allows you to reference array members by value instead of index, here to assign the empty list () to the range of elements from the first with value foo, to the last element (-1).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy