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 7716189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:34:29+00:00 2026-06-01T02:34:29+00:00

I´m building a bash script and i want to replace ${PRODUCT_NAME} with a WORD

  • 0

I´m building a bash script and i want to replace “${PRODUCT_NAME}” with a “WORD” for example.
The problem is “$”, in bash $ stands for an argument so when i run the script

echo "Replace ${PRODUCT_NAME} with $1 in document.txt"

for file in $(grep -il ${PRODUCT_NAME} ~/Documents/tmp/document.txt)   
do   
   sed -e "s/${PRODUCT_NAME}/$3/g" $file > /tmp/tempfile.tmp   
   mv /tmp/tempfile.tmp $file   
done   

the script recognizes the ${PRODUCT_NAME} as an argument and not as a word that i want to replace. How do i make it recognize that “${PRODUCT_NAME}” is a word and not an argument, so i can replace it?

  • 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-01T02:34:31+00:00Added an answer on June 1, 2026 at 2:34 am

    First of all, note that your sed script actually needs to use \${PRODUCT_NAME} rather than ${PRODUCT_NAME} as the search-pattern, because in a POSIX Basic Regular Expression, $ means “end of line” rather than “dollar sign”. That out of the way . . .

    In Bash, you can either quote a dollar-sign with a backslash:

    echo "Replace \${PRODUCT_NAME} with $1 in document.txt"
    
    for file in $(grep -il ${PRODUCT_NAME} ~/Documents/tmp/document.txt)
    do
       sed -e "s/\\\${PRODUCT_NAME}/$3/g" $file > /tmp/tempfile.tmp
       mv /tmp/tempfile.tmp $file
    done
    

    or else use single-quotes (which are like double-quotes except that they don’t allow $-based expansion, and don’t handle \):

    echo 'Replace ${PRODUCT_NAME} with '"$1 in document.txt"
    
    for file in $(grep -il ${PRODUCT_NAME} ~/Documents/tmp/document.txt)
    do
       sed -e 's/\${PRODUCT_NAME}/'"$3/g" $file > /tmp/tempfile.tmp
       mv /tmp/tempfile.tmp $file
    done
    

    (By the way, is it intentional that your echo line uses $1 while your sed line uses $3? It seems like they should both use the same parameter.)

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

Sidebar

Related Questions

I have a swf file (a flash game). I want to run some script
I use the below bash script for building an Eclipse workspace from command line.
I'm using this script for building application from command line: #!/bin/bash TARGET=signtest CONFIGURATION=Debug SDK=iphoneos
I have a java application and I want to run a script whenever it
I've got a speed question. I have a bash script which parses information from
For windows I just used a batch script to compile my program: @echo off
Building a comment system with Ajax and JQuery and I want the div the
I've been asked to modify a bash script at my internship and since yesterday
EDIT: SOLVED. Thank you everyone! I am building a shell script and I am
Building on the search example in this question , how would one use 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.