3

I have the following bash script to replace parenthesis for curly braces.

VARS=${VARS//(/{}
VARS=${VARS//)/}}

The first line works OK, but the second one will only add a curly brace at the end.

If I try to escape the curly brace with a backslash, the backslash itself gets stored in the variable.

Is there a different way to escape these curly braces from the string?

jasonsantos
  • 33
  • 1
  • 4

2 Answers2

1

You have to quote the first } so that bash does not think this is the end of the expression:

VARS=${VARS//)/\}}
phlogratos
  • 13,234
  • 1
  • 32
  • 37
1

Here is an alternative method:

VARS=`echo ${VARS} | tr '()' '{}'`

Although it seems like escaping the curly brace with a backslash is working, here is what I was using:

VARS=${VARS//(/{}
VARS=${VARS//)/\}}
Andrew Clark
  • 202,379
  • 35
  • 273
  • 306