Sample Header Ad - 728x90

How to POSIX-ly ignore "warning: command substitution: ignored null byte in input"?

2 votes
4 answers
1707 views
Today, I was working with my Raspberry Pi 4 with Debian 12 Bookworm, and I found it odd, that some system text files, namely I needed these two:
/sys/firmware/devicetree/base/model
/sys/firmware/devicetree/base/serial-number
were, upon reading and storing in a variable in bash like this:
rpi_model_name=$(cat /sys/firmware/devicetree/base/model)
rpi_serial_number=$(cat /sys/firmware/devicetree/base/serial-number)
producing the following warning
warning: command substitution: ignored null byte in input
I tried to get rid of the warning by redirecting stderr to /dev/null; for instance:
rpi_model_name=$(cat /sys/firmware/devicetree/base/model 2>/dev/null)
or
rpi_model_name=$(cat /sys/firmware/devicetree/base/model) 2>/dev/null
but we still get that annoying warning:
-bash: warning: command substitution: ignored null byte in input
I just have two shells installed, bash and dash. While dash behaves _normal_ as in without that warning; bash appears to be more _mouthful_ about this. So, at this point, I can't be sure if other shells _spit_ this or some similar warning too. My goal is to suppress this warning for all shells. I do not care about its origin or value, I just want it gone. The solution must be written POSIX-ly for portability.
Asked by Vlastimil Burián (30515 rep)
Jul 6, 2024, 07:47 PM
Last activity: Jul 15, 2024, 06:20 PM