Solved

ksh variable expansion when reading from an external file.

Posted on 2004-04-20
3
720 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
  • 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 50 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java core in Solaris 10 1 263
NTP Server in VMware 5 164
What is the meaning of mount pont? with respect to windows file server. 7 57
Control Number of Log Files -Perl 7 55
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

895 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now