Sample Header Ad - 728x90

Can't use combination of parentheses and variables in scripts

0 votes
0 answers
33 views
I have problems with replacing parentheses in combination with variables, in ssh. For instance, replacing (hello123blablabla) with (hello). So, it replaces all together, and parentheses as well, at least that's what I expect. But the variable value is lost when using the parentheses:
$ 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 follows:
perl -pi.bak -e s/\(hello[1..3].*?\)/(hello)/g file.txt
Asked by armagedescu (101 rep)
Jan 22, 2025, 03:00 PM
Last activity: Jan 22, 2025, 03:55 PM