Another approach is to use ls when reading the list of files in a directory to give you what you want, that is, "just the file name / s". In contrast to reading the full path to the file and then retrieving the file name component in the body of the for loop.
An example below that follows your original:
for filename in $(ls /home/user/) do echo $filename done;
If you run the script in the same directory as the files, it just becomes:
for filename in $(ls) do echo $filename done;
ryan Jul 13 '18 at 5:49 2018-07-13 05:49
source share