Puzzle: file name grepped from text file yields "no such file"

Dear all,
In a bash script, I grep a filename from an UTF8 encoded file:

LIST=`grep ^source $FILE | tr "\t" " " | cut -d " " -f 2 | sed -e 's,~,\$HOME,g'`

The result is

# echo $LIST
$HOME/.mail_aliases_seminaire_MMMG

Then I try to access it:

#ls $LIST
ls: cannot access $HOME/.mail_aliases_seminaire_MMMG: No such file or directory

while in the same script I can access the file hard coding its name

ls $HOME/.mail_aliases_seminaire_MMMG
/home/me/.mail_aliases_seminaire_MMMG

I wondered whether it's an encoding effect, however:

#echo $LIST | od -t oC -An > /tmp/CS
#echo '$HOME'/.mail_aliases_seminaire_MMMG | od -t oC -An | sdiff  - /tmp/CS
 044 110 117 115 105 057 056 155 141 151 154 137 141 154 151      044 110 117 115 105 057 056 155 141 151 154 137 141 154 151 
 163 145 163 137 163 145 155 151 156 141 151 162 145 137 115      163 145 163 137 163 145 155 151 156 141 151 162 145 137 115 
 115 107 012                             115 107 012

Any idea?

May be the shell did not expand the variable. Can you try as

ls "$LIST"
or 
eval ls "$LIST"
1 Like

Ah...when you have a variable which contains the name of another variable, that wont automatically be evaluated. So LIST contains $HOME, and you cant use that directly.
I think this article should help.

1 Like

Cheers ! Adding 'eval' did the trick.

And thanks Citaylor for your explanation and refs.

Btw, ~ counts as a variable, I hadn't originally the sed bit to replace it with $HOME and the same issue was showing already.