I have this while loop and here-document combo which I run in Bash 4.3.48(1) and I don't understand its logic at all.
while read file; do source ~/unwe/"$file"
done <<-EOF
x.sh
y.sh
EOF
My question is comprised of these parts:
What does the
read
do here (I always useread
to declare a variable and assign its value interactively, but I'm missing what it's supposed to do here).What is the meaning of
while read
? Where does the concept ofwhile
come in here?If the here-document itself comes after the loop, how is it even affected by the loop? I mean, it comes after
done
, and not inside the loop, so what's the actual association between these two structures?Why does this fail?
while read file; do source ~/unwe/"$file" done <<-EOF x.sh y.sh EOF
I mean,
done
isdone
... So why does it matter ifdone <<-EOF
is on the same line as the loop? If I recall correctly, I did have a case in which afor
loop was one-liner and still worked.
read
command that does." – Any or all of the sourced shell scripts (and their recursively invoked commands) can read from standard input and change the the loop invocations. – David Foerster Feb 07 '18 at 16:48... done 3<<-EOF
) and have theread
command read from unit 3 (while read file <&3; do ...
). – Gordon Davisson Feb 07 '18 at 21:00