I do not do perl, too arcane for me to learn, but I'll happyly use your code snippet. While you're at it, why don't you add the equivalent of "if filesize(Z)<$l: exit(1)" before truncate?
#!/bin/sh dd if=zImage-backup of=l skip=44 count=4 bs=1 b=$(echo $(echo -n '0000' | cmp -l l | cut -c3-5)) read a b c d <<EOF $b EOF rm l eval $(printf "l=\$(( (((0$d \* 256 + 0$c) \* 256 + 0$b) \* 256 + 0$a) ))") s=$(echo $(ls -l zImage-backup) | cut -f5 -d" ") if [ "$s" -gt "$l" ] ; then dd if=zImage-backup bs=$l count=1 of=zImage-backup.new && \ mv -f zImage-backup.new zImage-backup fi