You're using the wrong file descriptor. 1
is stdout, 0
is stdin.
Change:
while read CMD <&1; do
to:
while read CMD <&0; do
And it will from the file correctly. However, you don't need to do that all since read
defaults to using stdin:
while read CMD; do
Also, the -u
option can be used to read from a particular file descriptor (at least in bash). So you could do this as well:
while read -u 0 CMD; do