M
M
MasterCopipaster2021-08-28 14:58:03
bash
MasterCopipaster, 2021-08-28 14:58:03

To receive for processing of a cycle files on a mask from the folder sorted by date?

How can I get the files in a folder by mask, sorted by date (newest on top) and loop through them?
I am trying to do something like this:

$LS="ls -t | grep database"
for li in $LS
do
echo $li
done


but it does not work with the syntax that messed up.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
X
xotkot, 2021-08-28
@MasterCopipaster

$LS="ls -t | grep database"
for li in $LS
do
echo $li
done

the first
variable is incorrectly specified when assigning a value to it:
$LS=...
it will be correct: the
LS=...
second here you assign a string to the LS variable, and you need the result of the execution as a result, it should turn out something like this:
LS="ls -t | grep database"
LS="$(ls -t | grep database)"
LS="$(ls -t | grep database)"
for li in $LS
do
  echo $li
done

S
SOTVM, 2021-08-28
@sotvm

too lazy to write))
read line by line from $LS
https://itisgood.ru/2021/01/26/kak-chitat-fajl-pos...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question