You could also try replacing line 8 (VERS=...) with this one and let me know how that behaves. VERS=`dpkg -l | grep ^ii |grep linux-image|grep -v linux-image-generic|tr -s ' '|cut -d' ' -f3|sort -V | head -n -$NUM_TO_KEEP`
You could also try replacing line 8 (VERS=...) with this one and let me know how that behaves. generic| tr -s ' '|cut -d' ' -f3|sort -V | head -n -$NUM_TO_KEEP`
VERS=`dpkg -l | grep ^ii |grep linux-image|grep -v linux-image-