If your original purpose is to iterate through the list of files and directories present in the current directory, you don’t even have to run ls command for that.

for i in *; do
   echo "$i"
done

Alternately you can use ls to get the list of files and directories as shown below.

for i in `ls`; do
   echo "$i"
done

Other way of writing the above example is:

for i in $(ls); do echo "$i"; done;

The ls command can be used to select files of certain pattern. The following example selects only files will extension “.sh”.

for i in $(ls *.sh); do echo "$i"; done;