I am trying to process some files in directory using foreach loop for ls output:
IFS=$'\n'
for i in $(ls -1Atu); do
echo "$i"
done
At first time i thought it works, but when i created file with name like *
or filename*
, shell add additional iterations, because *
interpreted as wild char.
But if I escape ls output like for i in "$(ls -1Atu)";
, I'll get a single iteration, and $i will contain the output from ls entirely.
How can we solve this problem? I should note that any variants with ls -1Atu
preferable, as I need, what would the resulting files were sorted by atime.
Thank you