How can I escape curly braces at the end of a regular expression

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?


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//)/}}

你必须引用第一个}以便bash不认为这是表达式的结尾:

VARS=${VARS//)/}}
链接地址: http://www.djcxy.com/p/97060.html

上一篇: bash命令组:为什么大括号需要分号?

下一篇: 我如何在正则表达式的末尾转义大括号