The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk - arithemetic functions with external variables DKNUCKLES Shell Programming and Scripting 2 12-01-2007 04:32 AM
How to parse config variables from external file to shell script pradsh Shell Programming and Scripting 2 07-09-2007 02:21 PM
Accessing files on external USB drive using UNIX? Slanter UNIX for Dummies Questions & Answers 1 05-30-2006 01:47 AM
how to include external files in tcsh umen Shell Programming and Scripting 0 12-07-2005 05:54 AM
substituting shell variables suds19 Shell Programming and Scripting 1 10-16-2002 08:55 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-31-2008
oneillc9 oneillc9 is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 1
Substituting variables from external files

Hi All,

I have the following problem:

1. I have a file containing a line:
a,b,d,${d},e,f

2. From within a script I grep the file for '^a,' to get the line
3. I obtain the fourth field as follows:
Field4="$( print -r $fileEntry | cut -d, -f4 )"
4. The script exports variables at the beginning including ${d}

How do I get ${Field4} to contain the substituted variable ${d} instead of the literal '${d}'

I hope this is clear, I am happy to explain anything if I am talking jibberish.

Thanks in advance.

Chris
  #2 (permalink)  
Old 07-31-2008
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
Use eval to get the value of ${d}:

Code:
d=100
Field4="$( print -r $fileEntry | cut -d, -f4 )"  # Field4 is literal ${d}
eval "eval_var=$Field4"  # now $eval_var holds the value of ${d}
echo ${eval_var}    # should print 100
Regards
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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

BB 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 -4. The time now is 03:16 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0