This is very basic bash stuff. Let's go through your script.
for D in ls /l /media/user
do
You create a for-loop with the variable D which loops over
so, it will execute 3 times.
directory add -d D
I don't know what the program directory
is supposed to do; I don't know it. However, it is executed 3 times exactly the same way, with the same arguments:
done
The end of your for-loop.
That is not exactly the behavior that you describe; it will add always exactly 3 times litterally D
.
Now for the improvements.
You do not want to run exactly 3 times, but you want to run for every directory in /media/user
. So, an obvious choice would be to use $(ls -l /media/user)
. Now, I do not know what kind of format your directory
program expects as argument, but if it isn't
-rw-r--r-- 1 ljm users 27164672 Jun 19 00:30 mikrotik-6.47.10.iso
then you probably do not want the -l
option. Also, parsing the output of ls
is in general a bad idea. So, what you're probably looking for is
for D in /media/user/*
do
Next id your directory
program. It is always called with D
as last argument. Not the value of D
, that would be $D
. That means that you probably want to
directory add -d $D
But, if the directory name has a space in it, this will split the directory name into two arguments. So quoting is required:
directory add -d "$D"
Hope that gets you a bit better on track.
inotify
to monitor changes in /media/user/. – Jeremy Boden Jun 19 '21 at 16:24