Solved

ksh variable expansion when reading from an external file.

Posted on 2004-04-20
3
746 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 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
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 several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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…
Suggested Courses

622 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