Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8449613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:45:29+00:00 2026-06-10T10:45:29+00:00

I am running an old version of git and I am writing a script

  • 0

I am running an old version of git and I am writing a script that updates the host name configuration.

My problem is that I can’t figure out the right escape character combinations so that a variable is not mixed with the back-reference used in my regex.

Here is my best effort

#!/bin/bash
#code
foo=`ec2-describe-instances i-f95e4b82 | grep amazon | awk '{print $4}'`
sed -i "s/\(ec2-user@\)\(.*\)\(:repo\.git\)/\\1 $foo \\3/" /var/www/.git/config

This puts a space between the first back-reference and the variable foo. The hope is to not have that space between the first back reference and $foo. I suspect I could use a literal instead of the backreference, but the user names and repos may change.

Any ideas?

Edit

"s/\(ec2-user@\)\(.*\)\(:repo\.git\)/\\1$foo\\3/"

Does not produce the right answer because foo is amalgamated with the 1, producing the wrong back reference. I can’t figure out how to escape $foo.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T10:45:31+00:00Added an answer on June 10, 2026 at 10:45 am

    You need to isolate the $foo variable so you don’t need spaces around it to distingusih its name from the other surrounding characters. Try

    sed -i "s/\(ec2-user@\)\(.*\)\(:repo\.git\)/\\1${foo}\\3/" /var/www/.git/config
    

    If you want only a space after foo, then use

    sed -i "s/\(ec2-user@\)\(.*\)\(:repo\.git\)/\\1${foo} \\3/" /var/www/.git/config
    

    IHTH

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a build script that pulls the old version out of the plist
I have a client running an old version of magento. It appears that there
i got an webserver running and old version of gambio (xt:commerce fork). The error_log
I have a very very old PC that is running DOS and using an
Running my script through Devel::NYTProf showed that the following portion of code took up
We have an old version of DNN running as our production website (version 04.09.00).
Say you have a legacy website running on an old code-base that offers certain
I'm trying to debug an application on an embedded device running an old version
I'm having an issue where I can concisely prove that task scheduler is running
For some reason Xcode was running an old version of my app on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.