Richard W.M. Jones wrote:
On Wed, Nov 25, 2009 at 09:25:37AM +0100, Jim Meyering wrote:
First, on this kernels-assigning line,
kernels=$(ls -1vr /boot/vmlinuz-*.$arch* 2>/dev/null | grep -v xen; ls -1vr /boot/vmlinuz-* 2>/dev/null | grep -v xen)
if you add ls' -d option, that will prevent a false-positive match if /boot/vmlinuz-* ever matches a directory containing something whose name includes "xen".
Also, you can avoid duplicating the "2>/dev/null | grep -v xen" part by using a single invocatin of ls, and then I noticed that the expansion of the second glob, /boot/vmlinuz-*, would include anything matched by the first one, so this is adequate:
kernels=$(ls -1dvr /boot/vmlinuz-* 2>/dev/null | grep -v xen)
On rereading this, I understand the mistake.
The order that the kernels is presented in is significant, which is why we first search for $arch-specific kernels, and secondly for general kernels (in both cases avoiding Xen PV kernels).
Ahh.. good point. I hadn't looked at how $kernels was used. Keeping the two globs, you can still use only one ls invocation, (adding ls's -U (don't sort) option): kernels=$(ls -1duvr /boot/vmlinuz-*.$arch* /boot/vmlinuz-* 2>/dev/null \ | grep -v xen) Does it matter that ls's -v (version sort) option is relatively new? It was added in coreutils-7.0 (2008-10-05).