IFS="\n"
This sets IFS
to the two characters \
(backslash) and n
(lowercase letter N). Which means that later on, read
will split the input it gets on either of those. Now, the only line in your example with an n
is the and so on...
, but that's enough to see the result.
You probably meant to use
IFS=$'\n'
but as rightly noted in the comments, that wouldn't make much sense either, since read
would read only one line ending in a newline, then try to split into fields using newline as the separator. There won't be any in the later step.
If you want to loop over the lines of the input file, use
while IFS= read -r line; do ...
or if you want to read them to an array and loop over that:
mapfile -t lines < ...
for line in "${lines[@]}"; do ...
but see Why is using a shell loop to process text considered bad practice?
Also, this is a bit suspect:
done <<< $(cat "./dl.txt")
In general, the unquoted expansion would split the output from cat
into multiple words, but I think word splitting doesn't happen on the right-hand side of <<<
. But it would happen on the right side of a <
(possibly erroring with "ambiguous redirect"), so I would suggest putting that in quotes.
Or just use a process substitution:
... < <(cat "./dl.txt")
or just drop the cat:
... < dl.txt
while
loop the content of a variable that captures the output ofcat
ing a text file - just saywhile read ... done < dl.txt
. – AdminBee Nov 15 '21 at 12:17curl
with these URLs, just doxargs curl <dl.txt
. – Kusalananda Nov 22 '21 at 13:03read -a
? The-a
option makesread
create an array by splitting the line on the characters in$IFS
, but AIUI you're trying to set that to newline, and newline will never occur within a line (by definition, since it defined the end of the line). Furthermore, you then use the variable as if it weren't an array at all (${line}
just gets the first entry of an array), making it doubly useless. What are you actually trying to accomplish with the-a
? – Gordon Davisson Nov 22 '21 at 17:17[shellcheck.net](https://www.shellcheck.net/)
will point out several of the problems/confusions involved. I strongly recommend running all your scripts through it and fixing the things it points out. – Gordon Davisson Nov 22 '21 at 17:19