Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ksh variable expansion when reading from an external file.

Posted on 2004-04-20
3
Medium Priority
?
753 Views
Last Modified: 2013-12-27
Hi,

   I think this is an easy question!  I've got a text file where I store information that I want to read into a ksh script.  For example, the text file has a line:
abcdef|-p ${NAME}

   In my ksh script, I have defined the NAME variable (NAME="temp") but when I parse the line from the text file as follows (line has been read into variable REC):
TEXT=$(echo $REC|awk '-F|' '{print $2}')
the resulting TEXT variable contains:
-p ${NAME}
instead of:
-p temp

  Is there a way to get this variable expansion to work properly?

Thanks

0
Comment
Question by:KAG99
[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
  • 2
3 Comments
 
LVL 7

Expert Comment

by:fim32
ID: 10870235
hmm, i don't think ksh works that way...  unlike perl, there are no advanced q// options...
perhaps someone can correct me if i'm wrong?

the easiest way to do this, is to set your vars in your text file to some distinctive character string, like %%NAME%% (i've seen this one used)

and then after you've awked, sed the replacement:
TEXT=$(echo $REC|awk '-F|' '{print $2}'|sed -e "s/%%NAME%%/$NAME/")
0
 
LVL 3

Accepted Solution

by:
dtkerns earned 200 total points
ID: 10870973
you need to use eval to get ksh to do double substitution ... and an echo since eval needs to do something with the expresion

TEXT=`eval echo $(echo $REC|awk '-F|' '{print $2}')`
0
 
LVL 7

Expert Comment

by:fim32
ID: 10873119
ah, that pesky eval :P
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

721 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