I try to print and manipulate all filenames in current directory and there are some filenames containing whitespace. But when I use IFS=$'\nā
to delimite filenames, it also remove character "n" from filenames.
Here is my code
#!/bin/dash
IFS=$'\n'
for file1 in $(ls)
do
echo "$file1"
done
It should print
apple.txt
different.txt #
empty.txt
hello word.txt
ifstest.sh
one.txt #
same.txt
But the result is
apple.txt
differe #
t.txt #
empty.txt
hello word.txt
ifstest.sh
o #
e.txt #
same.txt
What should I do to avoid that?