I can only remember this because I initially didn’t learn about xargs
— so any time I need to loop over something I tend to use for var in $(cmd)
instead of cmd | xargs
. It’s more verbose but somewhat more flexible IMHO.
So I run loops a lot on the command line, not just in shell scripts.
Judging by the camera angle, OP may have been today years old when they learned this as well (I learned it well into my 30s, too).