Substituting variables from external files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Substituting variables from external files
# 1  
Old 07-31-2008
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  
Old 07-31-2008
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk - Why can't value of awk variables be passed to external functions ?

I wrote a very simple script to understand how to call user-defined functions from within awk after reading this post. function my_func_local { echo "In func $1" } export -f my_func_local echo $1 | awk -F"/" '{for (k=1;k<=NF;k++) { if ($k == "a" ) { system("my_local_func $k") } else{... (19 Replies)
Discussion started by: sreyan32
19 Replies

2. Shell Programming and Scripting

getting vars from external files

Hi I have an issue, I want to get variables from an external file. Variable file var1=test var2-test2 I want to get these vars from another shell script. Does any one know how? (5 Replies)
Discussion started by: digitalviking
5 Replies

3. Shell Programming and Scripting

Assign value to external variables from awk

Hello I have a text file with the next pattern Name,Year,Grade1,Grade2,Grade3 Name,Year,Grade1,Grade2,Grade3 Name,Year,Grade1,Grade2,Grade3 I want to assign to external variables the grades using the awk method. After i read the file line by line in order to get the grades i use this ... (2 Replies)
Discussion started by: Spleshmen
2 Replies

4. Shell Programming and Scripting

Editing external files

I am running Matlab in a unix enviroment and in my Matlab program I am calling an outside program (mav) to run with a unix command in Matlab: unix('mav -u 5 -c 1 -s') My goal is to edit the input files (three different files) for that external program and then run that external program... (0 Replies)
Discussion started by: heatona
0 Replies

5. Shell Programming and Scripting

reading external variables does not work

... declare vINIFILE vINIFILE=$1 ... echo "The name of the File is $vINIFILE" >>mail_tmp echo "" >> mail_tmp.$$ ... grep RUNJOB=0 $vINIFILE >>tmp_filter ... So the strange is in echo-statement I get the correct output for $vINIFILE wrtitten into the file mail_tmp. But the... (2 Replies)
Discussion started by: ABE2202
2 Replies

6. Programming

JAVA - External JAR files in UNIX

Hi, I have to run my JAVA programs in UNIX server. The java program uses some external jar files for compiling. I have set the classpath to the folder where all the jar files are present using EXPORT classpath command. But when i compile, it shows errors.. saying that the classes relating... (8 Replies)
Discussion started by: satish2712
8 Replies

7. Shell Programming and Scripting

awk - arithemetic functions with external variables

I'm trying to get awk to do arithmetic functions with external variables and I'm getting an error that I cannot figure out how to fix. Insight would be appreciated money=$1 rate1=$(awk -F"\t " '/'$converting'/{print $3}' convert.table) rate2=$(awk -F"\t"... (2 Replies)
Discussion started by: DKNUCKLES
2 Replies

8. Shell Programming and Scripting

How to parse config variables from external file to shell script

How do i use a config.txt to recursively pass a set of variables to a shell script eg my config.txt looks like this : path=c://dataset/set1 v1= a.bin v2= b.bin path=c://dataset/set2 v1= xy.bin v2= abc.bin .................. and so on . and my testscript : (2 Replies)
Discussion started by: pradsh
2 Replies

9. Shell Programming and Scripting

how to include external files in tcsh

Hello Simple question about tcsh , i like to make external file that some tcsh script will read from him var=="some value" how can i make the include in tcsh files? Thanks (0 Replies)
Discussion started by: umen
0 Replies

10. Shell Programming and Scripting

substituting shell variables

I have a script run_batch.sh as below :- PAR_VALIDATION=val_siconf PAR_RUN_LEVEL=1 PAR_EXCLUSIVE_RUN_YN=Y DATABASE_USER="/@"$TWO_TASK sqlplus -s $DATABASE_USER |& print -p -- 'set feed off pause off pages 0 head off veri off line 500' print -p -- 'set term off time off... (1 Reply)
Discussion started by: suds19
1 Replies
Login or Register to Ask a Question