Why looping over all existing archives, picking the latest version of the current archive, skipping it in case it's already in our list of selected latest versions or adding it otherwise?
The current code runs ls|sort|tail about n * (v - 1) times for n different libraries and v versions respectively since the globbed list is almost always sorted already, effectively adding the latest versions after skipping all others. This diff makes it much clearer and simpler by sorting and picking only as many versions as there are libraries to reorder (two). Globbing is done within the loop so future libraries with different naming schemes comes at no cost. Applies cleanly to both the current revision as well as my previous diff but the previous one will fail on top of this one. Feedback? Comments? Index: rc =================================================================== RCS file: /cvs/src/etc/rc,v retrieving revision 1.507 diff -u -p -r1.507 rc --- rc 4 Jul 2017 19:02:11 -0000 1.507 +++ rc 16 Jul 2017 01:15:43 -0000 @@ -171,13 +171,10 @@ reorder_libs() { echo -n 'reordering libraries:' # Only choose the latest version of the libraries. - for _liba in /usr/lib/libc.so.*.a /usr/lib/libcrypto.so.*.a; do - _liba=$(ls ${_liba%%.[0-9]*}*.a | sort -V | tail -1) - for _l in $_libas; do - [[ $_l == $_liba ]] && continue 2 - done - _libas="$_libas $_liba" + for _liba in 'libc.so.*.a' 'libcrypto.so.*.a'; do + _libas="$_libas $(ls /usr/lib/$_liba | sort -V | tail -1)" done + _libas=${_libas# } # Remount read-write, if /usr/lib is on a read-only ffs filesystem. if [[ $_mp == *' type ffs '*'read-only'* ]]; then