今天,我正在使用装有 Debian 12 Bookworm 的 Raspberry Pi 4,我发现一些系统文本文件很奇怪,我需要这两个:
/sys/firmware/devicetree/base/model
/sys/firmware/devicetree/base/serial-number
读取并存储在变量中bash
如下:
rpi_model_name=$(cat /sys/firmware/devicetree/base/model)
rpi_serial_number=$(cat /sys/firmware/devicetree/base/serial-number)
产生以下警告,我无法通过重定向stderr
来消除/dev/null
例如:
warning: command substitution: ignored null byte in input
提到的重定向看起来像这个命令片段;请注意,我们仍然会收到令人讨厌的警告:
rpi_model_name=$(cat /sys/firmware/devicetree/base/model 2>/dev/null)
-bash: warning: command substitution: ignored null byte in input
我刚安装了两个 shell,bash
和dash
。虽然没有那个警告,但dash
行为正常bash
;似乎更拗口。所以,目前,我不确定其他 shell 是否也会发出这个或类似的警告。
我的目标是在所有 shell 中隐藏此警告。我不关心它的来源或值,我只希望它消失。
为了可移植性,解决方案必须以 POSIX 形式编写。