This will only pick up one level of indirection. Consider

```
A=x
B=x
C=${A}-${B}
D=${C}
E=${D}
F=${E}
```
which ought to evaluate to

```
A=x
B=x
C=x-x
D=x-x
E=x-x
F=x-x
```

The only sensible way to do this is via topological sort. Which would be simpler than what you have written, anyway.