Regular Expressions 101

Community Patterns

Match Special Characters in BASH for variable assignments

1

Regular Expression
Python

r"
(?<!\W)[~#:@?!](?!\W)
"
gm

Description

BASH will not know that you are attempting to assign something. The parser will see varname with no = and treat it as a command name, and then pass = and vardata to it as arguments.

Match tilde, hash or colon special characters that have either a word character or a string-end on each side, you can use this pattern:

(?<!\W)[~#:@?!](?!\W)
Submitted by anonymous - 4 years ago