It's just a misunderstanding of the data type really, and you actually have the answer you probably wanted if you're willing to ignore the warning.
You can see this by sending your result to stdout
using echo
(remember, cat
gave a warning - not an error):
$ mcuSerialNumber=$(cat /sys/firmware/devicetree/base/serial-number)
-bash: warning: command substitution: ignored null byte in input
$ echo $mcuSerialNumber
00000000eccd2fff
Let me attempt an explanation: The data at /sys/firmware/devicetree/base/serial-number
is a null-terminated string - which cat
is not designed to handle - at least not without a squawk.
You have two choices: ignore the squawk/warning, or read it using a different method; e.g.:
- using the little-known
strings
utility:
$ strings /sys/firmware/devicetree/base/serial-number
00000000eccd2fff
$tr < /sys/firmware/devicetree/base/serial-number -d '\0'
00000000eccd2fff
$ sed 's/\0//' /sys/firmware/devicetree/base/serial-number
0000000eccd2fff
$ awk -F /0 'NR == 1 { print $0 }' /sys/firmware/devicetree/base/serial-number
00000000eccd2fff
Alternatively, the same serial number is also available in the file /proc/cpuinfo
file, but not a null-terminated string, so you can do something like this:
$ grep Serial /proc/cpuinfo
Serial : 00000000eccd2fff