The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM
Home Forums Register Rules & FAQ Members List Arcade Search Today's Posts Mark Forums Read


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.


Other UNIX.COM Threads You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
variables in shell viko Shell Programming and Scripting 2 03-03-2008 07:09 PM
Double Substitution variables in ksh xiamin Shell Programming and Scripting 19 05-23-2007 01:35 AM
Using shell variables In awk nortypig Shell Programming and Scripting 11 08-23-2006 09:48 PM
Newlines in shell variables narcvs Shell Programming and Scripting 4 03-15-2006 01:58 PM
substituting shell variables suds19 Shell Programming and Scripting 1 10-16-2002 05:55 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-02-2008
Registered User
 

Join Date: Mar 2008
Posts: 17
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
shell variables and sed substitution

My specific goal: automatically edit a Makefile variable's (EXTRAVERSION)
value in a kernel Makefile.


So, I have a shell script that takes one parameter, a version string:

buildkernel.sh 2.6.18.21.7-custom

In the script, I assign the parameter to K_VER:

K_VER="2.6.18.21.7-custom"

I perform string operations until I get this:
XTRA_K_VER=".21.7-custom"

I export it (thinking that the proper value would be substitued when
make was run, but the variable is not expanded):
export XTRA_K_VER

So, maybe I should forget the export?

I am using the variable, XTRA_K_VER, in a substitution in a
Makefile with the idea that the variable would be expanded:

sed -f script.sed <Makefile.old >Makefile.new

where script.sed contains the following:

s#\([[:blank:]]*EXTRAVERSION\)[[:blank:]]*=[[:blank:]]*.*#\1 = $XTRA_K_VER#

The issue I am experiencing is that I want the value of XTRA_K_VER to
be used in the Makefile as opposed to the literal variable name. I do not
have a preference whether I insert the variable form of the entity (into
the Makefile) or the literal string value of the variable.

From what I have described, is there a reasonably clean way to let the
sed script expand the value of the variable before the substitution? I
thought about re-writing the sed script dynamically upon every invocation
of the program, but that seems a bit extreme to me (and potentially
challenging for others to maintain in the future).

Thanks in advance. I really appreciate the experience of the people on this site.

Cheers,
:-D
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-02-2008
Registered User
 

Join Date: Mar 2008
Posts: 17
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
ya know.. I think i was merely missing parens around the variable
written into the Makefile. D'oh!
Reply With Quote
  #3 (permalink)  
Old 05-04-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 2,203
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
That's right. Also just for the record, the "export" doesn't add anything; the variable is interpolated by Make itself before the command executes. (Export is for putting stuff in the environment, so you can e.g. modify the PATH of all the processes you run from your Makefile.)
Reply With Quote
Google UNIX.COM
Reply



Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -7. The time now is 04:03 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger

Search Engine Optimization by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102