I would want to iterate over contents of a directory and list only ordinary files. The path of the directory is given as an user input. The script works if the input is current directory but not with others. I am aware that this can be done using ls.. but i need to use a for .. in control structure.
#!/bin/bash
echo "Enter the path:"
read path
contents=$(ls $path)
for content in $contents
do
   if [ -f $content ];
   then
       echo $content
   fi
done
 
     
     
     
    