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

  • Home
  • SEARCH
  • 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 1022891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:31:57+00:00 2026-05-16T11:31:57+00:00

I saved a value by shell command: For example: timeoutvalue=`echo timeout=2.0` And I have

  • 0

I saved a value by shell command:
For example:

timeoutvalue=`echo "timeout=2.0"`

And I have to grep the value of timeout from another text, and replace it with this timeoutvalue.
For example, the text is egtest:

<host ip="255.255.255.0" name="testhost" description="hostfortest" connection="xmlrpc" timeout=4.0/>

I want to grep the value of timeout from the above text and replace the value of timeout=4.0 by timeout=2.0(the value I saved as variable by shell command).

My problem is:
(1)for a simple test, I want to replace the value of timeout=4.0 with $timeoutvalue.
So my command is:

sed 's/timeout=4.0/$timeoutvalue/g' egtext.

But it seems the text become:

<host ip="255.255.255.0" name="testhost" description="hostfortest" connection="xmlrpc" $timeoutvalue/>

Could anybody tell me why it is wrong?

(2)For this problem, I have to first grep timeout=4.0 from the text, and replace the value 4.0 to the saved variable value(in my example:2.0).
I thought but I don’t know which command to use to realize this(awk? sed?)
Because the filed of the text isn’t certain,(for example, in this text, timeout is in $5, but maybe in another text, it maybe changed into $6). I mean it may be changed into:

<host ip="255.255.255.0" name="testhost" description="hostfortest" connection="xmlrpc" type="onebox" timeout=4.0/>

Could anybody help me with this?

  • 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-05-16T11:31:57+00:00Added an answer on May 16, 2026 at 11:31 am

    Single quote does not allow variable interpolation, so use double quotes as:

    sed "s/timeout=4.0/$timeoutvalue/g" egtext
    

    EDIT:

    Consider

    who='world'
    echo "Hello $who" # prints Hello world
    echo 'Hello $who" # prints Hello $who
    

    as seen single quotes does not allow variable substitution. It treats $who literally as a dollar followed by who. But double quote behaves differently, when it sees $who it realizes that who is a variable and replaces $who with its value.

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

Sidebar

Related Questions

I have a date converted to double value and saved in database. Now, I
I have a datatable which contains yearly data saved. e.g. dtDate Value 2010-01-01 00:00:00.000
I have been trying to program a UNIX style shell command prompt in C.
I'm simulating a todo list where the textfield's value gets saved in the model
When I change and synchronize value in my app, they get saved, but the
In SharePoint 2007, when I saved a document to a document library, the value
I have configuration values saved in an app.config . I want to create a
I have been trying to use/save the boolean value of a checkbox in other
Let's suppose I have a struct like this: struct my_struct { int a; int
I have multiple variables in a shell script; i was trying to save some

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.