Solved

A very very simple script

Posted on 2006-11-02
1
261 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 45

Accepted Solution

by:
sunnycoder earned 20 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

636 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