Suppose I\'ve got a list of files
file1
\"file 1\"
file2
a for...in loop breaks it up between whitespace, not newlines:
for
Actually, Mark's suggestion works fine without even doing anything to the internal field separator. The problem is running ls in a subshell, whether by backticks or $( ) causes the for loop to be unable to distinguish between spaces in names. Simply using
for f in *
instead of the ls solves the problem.
#!/bin/bash
for f in *
do
echo "$f"
done