Check that the byte exists before trusting a zero. A number alone cannot distinguish a stored 00 from a read outside the file.
Start with three known bytes
Run this over SSH. The subshell removes its private sample on exit. The printf escapes are octal. Compare them with the hexadecimal view from -C.
(
d=$(mktemp -d) || exit 1
trap 'rm -f "$d/sample"; rmdir "$d"' EXIT
printf '\033\377\000' >"$d/sample"
busybox hexdump -C "$d/sample"
for i in 0 1 2; do
printf 'offset %s = ' "$i"
busybox hexdump -s "$i" -n 1 -e '1/1 "%u"' "$d/sample"
printf '\n'
done
)
Offsets start at zero. Expect 1b, ff and 00 to give 27, 255 and 0. The final 00000003 is the length. Offset 2 is the last valid position.

The OpenWrt 25.12.6 x86/64 VM shows the individual commands that the loop repeats. Check the sample on your own build.
Why -n 1 alone is insufficient
The -s option selects the start and -n limits total input. In the -e format, 1/1 means one repetition consuming one byte. The first 1 alone leaves the width unspecified. %u prints unsigned decimal. Byte order does not affect one byte.
Read the fifth byte of a backup
Replace backup.bin with an existing regular file. The guard reads offset 4 only if at least five bytes exist. If it skips the read, check the path and units.
n=$(wc -c < backup.bin) && [ "$n" -gt 4 ] && {
busybox hexdump -s 4 -n 1 -C backup.bin
busybox hexdump -s 4 -n 1 -e '1/1 "%u\n"' backup.bin
}
If -C shows 00, zero is correct. If ff gives zero, check the offset and executable, record the build and revert your script. Avoid writing data until both views agree. Share the sample only. Backups may contain keys.
Does an OpenWrt backup contain Wi-Fi and PPPoE passwords? Check without printing them
Comments