I have bash strings enclosed by []
, e.g. [name], [surname]. And want to remove the starting [
and closing ]
. What can I do?
1 Answer
Given
$ echo "$var"
[name]
then either
using a string slice (removes the first and last characters - regardless of what characters they are)
$ echo "${var:1: -1}" name
using pattern substitution (globally removes
]
and[
regardless of where they occur in the string)$ echo "${var//[][]/}" name