Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

A very very simple script

Posted on 2006-11-02
1
Medium Priority
?
264 Views
Last Modified: 2012-05-05
Hi All ,

 Just a simple script . Trying to read 2 variables from user. And then replace the occurance of the  first variable with the second one in a particular file /tmp/test.

 But somehow (i guess so) the sed is not able to read the contents of a variable. ie. $orig and $name values.

 Should be matter of some extra characters to be used in sed . Plz help.

Script :-

 
 #!/bin/bash
 echo "Put original word"
 read orig
 echo " Put your name "
 read name
 cat /tmp/test | sed 's/$orig/$name/' > /tmp/test
 tail /tmp/test/  -n 1

 

0
Comment
Question by:harmsingh
1 Comment
 
LVL 45

Accepted Solution

by:
sunnycoder earned 60 total points
ID: 17864229
Hi harmsingh,

Use double quotes instead of single quotes ... Variables are read by shell and shell does not "peek" into anything enclosed in single quotes

sed "s/$orig/$name/"

Cheers!
sunnycoder
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question