Variable resolution in File content

I have a file File1 containing lines like below

apple ${FRUIT}-Color
orange ${FRUIT}-Color
banana ${FRUIT}-Color

Now, in my shell I'm reading the file like below

while read FRUIT DESC; do echo $FRUIT $DESC; done < File1

which outputs -

apple ${FRUIT}-Color
orange ${FRUIT}-Color
banana ${FRUIT}-Color

but what I want it -

apple apple-color
orange orange-color
banana banana-color

Any suggestions?

while read FRUIT DESC; do eval echo $FRUIT $DESC; done < File1

(don't let that input file out of your sight ;))

$ ls -l
total 16
-rwxr--r--  1 scott  staff  64 25 Jul 21:48 myScript
-rw-r--r--  1 scott  staff  82 25 Jul 21:49 file
$ 
$ cat myScript
while read FRUIT DESC; do
  eval echo $FRUIT $DESC
done < File
$ 
$ cat file
apple ${FRUIT}-Color
orange ${FRUIT}-Color
banana ${FRUIT}-Color $(rm file)
$ 
$ ./myScript
apple apple-Color
orange orange-Color
banana banana-Color
$ 
$ ls -l
total 8
-rwxr--r--  1 scott  staff  64 25 Jul 21:48 myScript

Thanks! I tried a few eval combinations but guess not this one :frowning: I feel so stupid :smiley:

The trick to getting eval to work is to put it in 'echo' first.

If echo prints valid shell statements, eval will work.

If echo is not printing valid shell statements, eval will choke on it.