Note that if any of your filenames have whitespace, you will have problems. When you iterate over a variable with for
, you are iterating over the whitespace-separated words in that variable. To safely iterate over files, regardless whether they have spaces in the names, don't store the list of files in a plain variable.
Most straight-forward way:
for f in /home/stef/test/*; do
# ...
If you want to hold the filenames in some kind of container, you need to use an array:
files=( /home/stef/test/* )
for f in "${files[@]}"; do
# ...