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

Use eval to get the value of ${d}:

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