BASH Shell: For Loop File Names With Spaces – nixCraft

I’ve been wondering how to do this. I didn’t realise I could do this in so many different ways. Simplest way, I think:

$ ls
2013.doc externalIP.txt Introduction to Compositing in Blender.txz
externalIP.sh Ideas.odt Piano to Learn
$ for a in
ls *; do echo $a; done
2013.doc
externalIP.sh
externalIP.txt
Ideas.odt
Introduction
to
Compositing
in
Blender.txz
Piano
to
Learn
$ SAVEIFS=$IFS
$ IFS=$(echo -en “\n\b”)
$ for a in ls *; do echo $a; done
2013.doc
externalIP.sh
externalIP.txt
Ideas.odt
Introduction to Compositing in Blender.txz
Piano to Learn
$ IFS=$SAVEIFS
$ for a in ls *; do echo $a; done
2013.doc
externalIP.sh
externalIP.txt
Ideas.odt
Introduction
to
Compositing
in
Blender.txz
Piano
to
Learn
$

BASH Shell: For Loop File Names With Spaces – nixCraft.