As far as I know, find . -maxdepth 1 -type f is the only reliable way to get the list of files in a folder. However, naively putting the output of this command in a bash array (($(find . -maxdepth 1 -type f)) is going to fail if some files have spaces in their names.
What is the correct way to do this?
The safest way is to use
findwith-print0which will also handle filenames with newlines in them correctly. Loop over the files and store them in an array:Test: