There is code that should work in bash and zsh. The code snippet lists all directories, sorted by last modified time. He solves this problem quite successfully. The listed directories are generated by the same code and contain only a-zA-Z0-9-_ characters, no spaces.
mcve.sh:
#!/usr/bin/env bash for i in $(ls -dt1 ./*/); do echo "${i}"; done I use shellcheck:
shellcheck mcve.sh I get the following result:
In mcve.sh line 2: for i in $(ls -dt1 ./*/); ^-- SC2045: Iterating over ls output is fragile. Use globs. What is the "fragility" of this method? How can I improve it?
The obvious option "use globy" is not suitable, because need sorting by time.
abfor file name will split into 2 -aandb(yes, @alexander barakin has already answered in detail, and made recommendations better than in the accepted answer) - avp