I can't understand, how in the world does for loop delimit it's items.
>a for loop can loop through a variable containing filenames
>a for loop "can" loop through variable containing lines of text from a file. (lines in varaible what?)
This:
Code:
for item in $var
do
command $item
done
means that for each "item" in $var for loop will execute "command $item"
$var could be also replaced by something like `cat file` or output of any other command. The thing after "in" is actually like the real input of the "for" bash-included command.
But I don't understand and have never heared anyone say how are those items delimited.? Does for loop actually loop through lines of it's "input?" Does it loop through words separated by whitespaces?
Only after boring experimentation I have determined that items in a for loop are in fact only delimited by whitespaces, not by lines or anything else. And articles like this one
https://linuxhint.com/bash_for_each_line/ or any other instance of suggesting that for loop can loop through lines in a file is a lie and is only true in a case where new lines are the only whitespaces.
This should be a common knowledge, but it isn't even for people who explain how a for loop works. Either that or they do stupid things like suggesting for loop is looping through "lines" or through "files" on purpose to confuse anyone who actually wants to understand how it works, and give them a headache when they try to finally loop through a list of files with spaces in names (I see now, this is one of the real reasons to not put spaces in filenames so you can use for loop on them). This is not even funny that I'm doing experiments and backwards engineering for loop to learn that. It's just sad and utterly retarded.
All it takes to properly explain for loop in bash is something like
The "for" loop:
Code:
for <item> in <list of items delimited by whitespaces>
do
command $item
done
But noone does it. Either that or my ego just doesn't allow me to learn from anywhere else than my own experience. For me This is like noone who "knows" wants to actually teach you anything, everyone who knows wants to only tell you enough to be useful to him. This is like a medival priest speaking to peasants about god but keeping them illiterate so they can't read the bible themselves.