I have a function and its first argument is the string with stored path to some directory.
This string is output of the find . -type d.
If I list all the files in the current dir, its simple
for file in *; do
commands
done
But with the string it doesn’t treat it that way of course.
for file in "$1"; do
commands
done
So I thought to use ls
for file in `ls "$1"`; do
commands
done`
But with this solution it simply can’t handle the files with space, after some
research I’ve found everywhere a recommendations to use find but I don’t get, find will
list all the files/dirs/subdirs, simply the whole tree, but I want just the stuff in the current dir.
I will be very thankful for every help.
UPDATE
I’ve tried one more thing that seems to work:
pushd "$1"
for file in *; do
echo "$file"
done
popd
But I would prefer some solution where I don’t have to change my working dir
If you only want non-dot files, the following should do the trick.
More flexible is the following code.