Since $VAR
is a list of filenames, I assume you need the files concatenated together, then redirected to the while loop. I think something like the following should work in bash:
$ VAR="
/etc/networks
/etc/papersize
"
$ while IFS=" " read token; do
BUFFER="$BUFFER $token"
done < <( cat $VAR )
$
$ echo $BUFFER
# symbolic names for networks, see networks(5) for more information link-local 169.254.0.0 letter
$
Note the <( )
process substitution is bash-specific, so probably won't work with sh.
Since you need something to work in sh, you can just put this the while loop in a for loop over all the filenames:
#!/bin/sh
VAR="
/etc/networks
/etc/papersize
"
for f in $VAR; do
while IFS=" " read token; do
BUFFER="$BUFFER $token"
done < $f
done
echo $BUFFER