My aim is to find $files on some $devices and save them to one or more folders which are namend corresponding to a timestamp of each file. To get the timestamp I wanted to use stat.In contrast to echo $files, stat doesn't process each file separately. Instead it seems to process all files at once when I use .Do you have any suggestions on how to improve quoting or any other hints on how to make stat able to do what i want it to do? Thank you very much for your help.#!/bin/bashfor devices in $(ls /media/*/);  do    for files in $(find /media/*/$devices -iname *.jpg);      do        echo $files   # prints all files in separate lines        stat $files   # seems to process all files at once        stat $files     # splits file paths at spaces      done  done
get timestamp of files presented by FOR loop
stat;for
The problem is not with stat but with the source data in your for loop; because you have enclosed it all in quotes it becomes one long single entity.To fix this, remove the quotes around it, thus:for files in $(find /media/*/$devices -iname *.jpg);It works provided that none of the files or paths have spaces. But there is a more elegant solution which works with spaces and even with weird filenames (for instance ones that include quotes or newlines):while IFS= read -r -d '' file; do    # operations on each $file heredone < <(find /media/*/$devices -type f -iname *.jpg -print0)