0

I have two variables -

regex="<version>[0-9]*\.[0-9]*\.[0-9]*[^<]*<\/version>"
updated_regex="<version>${main_version}\.${feature_version}\.${patch_version}${tag}<\/version>"

Which i want to use in following command -

sed "s/$regex/$updated_regex/1" pom.xml 

But it is not working as the regex and variables are not being evaluated or substituted in my command.

2
  • The variables in updated_regex are expanded as soon as you run the line assigning the updated_regex variable, NOT when you run the sed line.
    – confetti
    Aug 1, 2018 at 19:12
  • it is prompting to wait for 5 mins๐Ÿ˜…๐Ÿ˜…๐Ÿ˜…
    – monster
    Aug 1, 2018 at 19:18

1 Answer 1

1

As I already said in my comment, when you run the line

updated_regex="<version>${main_version}\.${feature_version}\.${patch_version}${tag}<\/version>"

the variable updated_regex will be assigned that string, where all those variables will be expanded at the moment you run this line.

When you run the sed line this string will be used, but the variables inside the top line won't be expanded again. So the solution is to use the following:

regex="<version>[0-9]*\.[0-9]*\.[0-9]*[^<]*<\/version>"
sed "s/$regex/<version>${main_version}\.${feature_version}\.${patch_version}${tag}<\/version>/1" pom.xml 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .