delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/05/24/05:09:53

X-Spam-Check-By: sourceware.org
Message-ID: <465556A5.EA670B28@dessent.net>
Date: Thu, 24 May 2007 02:11:01 -0700
From: Brian Dessent <brian AT dessent DOT net>
X-Mailer: Mozilla 4.79 [en] (Windows NT 5.0; U)
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: Can I use a variable in sed?
References: <f33jbo$cnq$1 AT sea DOT gmane DOT org>
X-IsSubscribed: yes
Reply-To: cygwin AT cygwin DOT com
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

Jerome Fong wrote:

> I'm trying to write a script that allows me to change the port number
> depending on when environment I'm in.  I can pass in the port number to
> my script, but I stuck trying to get sed modify my file with my port
> number variable.   Here is the line I'm executing
> 
> sed '1,$ s^8080^$Shutdown_Port^' <./temp.xml >./server.xml
> 
> Since my line started out to be
> <Server port="8005" shutdown="SHUTDOWN">
> 
> Since Shutdown_Port was 9300, I thought the resulting line would be
> 
> <Server port="9300" shutdown="SHUTDOWN">
> 
> Instead, I got:
> 
> <Server port="$Shutdown_Port" shutdown="SHUTDOWN">
> 
> What am I doing wrong here?  Can sed be passed a variable?

This isn't Cygwin-specific at all.

You've used $Shutdown_Port inside a single-quoted string.  Shell
variable expansion does not occur there; that's the whole point of
single quotes.  

$ var=value; echo '$var is $var'; echo "$var is $var"; \
             echo '$var is '$var' is $var'
$var is $var
value is value
$var is value is $var

Brian

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019