Command substitution not working

Trying find and replace with the following code:

#!/usr/bin/env ruby

file_names = [‘foo.txt’]

file_names.each do |file_name|
text =
new_contents = text.gsub(/ADMIN_URL="t3:./,
'ADMIN_URL="t3s://hostname -f.

To merely print the contents of the file, use:

 puts new_contents

# To write changes to the file, use:, "w") {|file| file.puts new_contents }

But command substitution is not happening. Not sure what is the issue
here. Any help?

You need to use double quotes & string interpolation.

When you use single quotes you are saying that it should take the
characters inside in a literal way & not perform any kind of operations
with them.


text.gsub(/ADMIN_URL="t3:.*/, "ADMIN_URL=“t3:#{something}”)

I hope that helps.

  • Jesus Castello,

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs