I need to iterate through every file inside a directory. One common way I saw was using the for loop that begins with for file in *; do. However, I realized that it does not include hidden files (files that begin with a .). The other obvious way is then do something like for file in `ls -a`; doHowever, iterating over ls is a bad idea because spaces in file names mess everything up. What would be the proper way to iterate through a directory and also get all the hidden files?
proper way to iterate through contents in a directory
shell script;ls;wildcards;for;dot files
You just need to create a list of glob matching files, separated by space:for file in .* *; do echo $file; doneEditThe above one can rewrite in different form using brace expansion for file in {.*,*}; do echo $file; doneor even shorter for file in {.,}*; do echo $file; doneAdding path for selected files:   for file in /path/{.,}*; do echo $file; doneFor completeness it is worth to mention that one can also set dotglob to match dot-files with pure *.shopt -s dotglob