this post was submitted on 05 Jan 2026
18 points (95.0% liked)
Linux
11550 readers
787 users here now
A community for everything relating to the GNU/Linux operating system (except the memes!)
Also, check out:
Original icon base courtesy of lewing@isc.tamu.edu and The GIMP
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Wouldn't
for i in "$LIST";just result in a single loop iteration with$ibeing the entirety of$LIST?It would not, as @Quibblekrust@thelemmy.club explained in their comment (which I neglected to include in my explanation), Bash uses a special variable called
IFSwhen executing for loops like this.IFSstands for Input Field Separators, and is a list of one of each type of whitespace (tab, space, and newline), and uses these as separators automatically.So instead of taking that whole
lsoutput as one string of text, the for loop automatically separates it into an iterable list of strings using the newline separator.I'm pretty sure that IFS does not apply to quoted strings since word splitting happens before the quote removal (see Shell Expansion).
I didn't realize that. Thanks for pointing that out!
Which makes it real fun when you have spaces in filenames!
Really you shouldn't use ls as input to for. Use find -exec or something.