I am trying to list all the directory latest modified folder first using select
, but I am stuck.
Let's say I have:
Folder1
ThisIsAnotherDir
Directory
New Directory
This IS not_Same Directory
When I run following command:
ls -t -d */
I get the desired output.
But when I use select
:
options=$(ls -t -d */)
select d in $options; do test -n "$d" && break; echo ">>> Wrong Folder Selection!!! Try Again"; done
It lists the folder modified first, but, if I modified New Directory
last and run this, it outputs:
1)New
2)Directory
3)Folder1
4)ThisIsAnotherDir
5)Directory
6)This
7)IS
8)not_Same
9)Directory
I also tried:
select d in "$options[0]"; do test -n "$d" && break; echo ">>> Wrong Folder Selection!!! Try Again"; done
It fails also.
I hope this make sense. Thank you
select d in */
– Bodo Sep 01 '20 at 08:12echo "$options[@]"
just before the select line. This should help you to understand what it is happening. In any case,"$options[0]"
is only the first element of the array, I suppose you should use@
and not0
. – andcoz Sep 01 '20 at 09:26ls
(and what to do instead)? – pLumo Sep 01 '20 at 10:44