armagedescu
armagedescu

Reputation: 2155

Can't use combination of parenthesis and variables in scripts

I have problems with replacing parenthesis in combination with variables, in ssh. For instance, replacing (hello123blablabla) with (hello). So, it replaces all together, and parenthesis as well, at least that's what I expect. But the variable value is lost when using the parenthesis:

>hellovar=hello
>perl -pi.bak -e 's/\(hello[1..3].*?\)/($hellovar)/g' file.txt

The command is printed as following

>echo perl -pi.bak -e 's/\(hello[1..3].*?\)/($hellovar)/g' file.txt
perl -pi.bak -e s/\(hello[1..3].*?\)/($hellovar)/g file.txt

But I need it to be translated as following:

perl -pi.bak -e s/\(hello[1..3].*?\)/(hello)/g file.txt

Upvotes: 0

Views: 27

Answers (0)

Related Questions