0

This while loop works perfectly:

while read -r line
    do
        eval ${line}
    done < "${FILE}"

However, if I try to use an array for input, it fails.

while read -r line
    do
        eval ${line}
    done < "${array[@]}"

Is it just not possible, or am I doing something incorrectly?

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Gerard
  • 11
  • 1
  • What is that code supposed to do? – melpomene Oct 20 '17 at 13:29
  • Shell redirection syntax *only* shuffles file descriptors around -- changing which file handles are open on which descriptors. It doesn't do any other kind of magic, such as making variable contents available as file-like objects. – Charles Duffy Oct 20 '17 at 13:39
  • 1
    For that you need *different* syntax (though generally, transforming an array into a stream isn't a good idea -- the only way to represent arbitrary array contents unambiguously would be to make the stream NUL-delimited; that's doable, with, say, `done < <(printf '%s\0' "${array[@]}"`, and then `while IFS= read -r -d '' item`, but... *why* do that rather than iterate over the array directly?). – Charles Duffy Oct 20 '17 at 13:42

0 Answers0