Reading variables from a file

Hi,

I have an issue that hope someone will be able to help me with....

I'm using a while-read loop to read lines from a file that contain variables, and I want the variables substituted, but I can't get it to work - the below example with explain:

while read line
   do
      echo $line
      ls -l $line
done < testdata

testdata just contains "$HOME".

I want it to output:

"/export/home/aperp5" - this is what $HOME is set to
and then list the contents of $HOME

But it outputs:

$HOME
$HOME: No such file or directory

How can I get it to resolve the variable.

Regards,
Andy

Well normally you input or output (to) a file, meaning either read/write to it, not interpret its content... why put $HOME in a file rather than straight ahead

 <$HOME

? (because of the garbage .(dot) stuff?) or not use

pwd>testdata

before to use testdata

That was just a simple example, in reality we will have a file that contains lots of files, and actions that we want to do with them. All the file names will begin with variables like $ORACLE_HOME etc.. i.e:

DELETE:$ORACLE_HOME/bin/test.log

We will then then cut out the action and apply it to the file - there could be a long list of files.

We just need it to substitute the variable value, rather than keeping the variable itself.

Regards,
Andy

add 'eval'

eval ls -l $line

1 Like

You will have more responses if you display a sample of the input and desired output.

Thanks vgersh99, that worked a treat!!