As part of a bash script, I am running a regex substitution to insert values of octopus variables into a pre-existing config file.
For example, if I have a variable FOO defined in my project having the value BAR,
the line
FOO = ""
will be replaced in the file with
FOO = “BAR”
However, the line is instead being replaced with
FOO = “Unrecognized variable “FOO””
I am using this perl substitution in my script: perl -pi -e "s/^(.*) = \"\"$/\1 = \"$(get_octopusvariable "\1")\"/" $file
It calls the get_octopusvariable function with the pattern matched on the left of the = sign.
With the example I gave above, I can directly run ‘get_octopusvariable “FOO”’ and it returns “BAR” as expected, but when it executes as a part of the regex substitution, it instead returns “Unrecognized variable “FOO””
Any insight into why this is happening would be greatly appreciated.
Thanks!
Thanks for getting in touch. I was able to reproduce the issue but I’m not sure what is happening. We encode the variable name and then do a simple look-up to retrieve it’s value. I’m guessing the variable name is slightly different when executed via perl but I’m not exactly sure why. I’m going to talk with one of my colleagues and then I’ll follow-up here.
Thanks for the reply. I also tried doing the regex substitution with sed but I ran into the same issue. There must be something going on under the hood with perl and sed that is affecting the look-up. Anyway, I ended up just writing a bash script to do the replacements and it gets the job done.
It’s great to hear you got it working. It’s strikes me as odd that perl and sed change the string. We’ll keep this in mind as we make enhancements to this area in the future.