Solved

A very very simple script

Posted on 2006-11-02
1
251 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 20 total points
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now