Normally, example shows usage like:
for i in $(ls); do echo ${i}; done
But if there is a file (or directory) named " screw", then the above line will give out wrong result.
How to solve?
Normally, example shows usage like:
for i in $(ls); do echo ${i}; done
But if there is a file (or directory) named " screw", then the above line will give out wrong result.
How to solve?
No please don't use/parse ls
's output. Use it like this:
for i in *; do echo "${i}"; done
Alternatively you can use printf
(thanks to @ruakh):
printf '%s\n' *
IFS="$(echo -e "\b\r")";
for f in $(ls); do
echo "$f";
done
In case you are forced to stick to parsing ls output (which you shouldn't)