-1

I have bash strings enclosed by [], e.g. [name], [surname]. And want to remove the starting [ and closing ]. What can I do?

1 Answer 1

1

Given

$ echo "$var"
[name]

then either

  1. using a string slice (removes the first and last characters - regardless of what characters they are)

    $ echo "${var:1: -1}"
    name
    
  2. using pattern substitution (globally removes ] and [ regardless of where they occur in the string)

    $ echo "${var//[][]/}"
    name
    

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .