我的脚本尝试收集执行时 STDIN 中可能存在或不存在的信息,但如果管道为空,则 cat 会挂起。如果 STDIN 中没有任何内容,如何确保我的脚本跳过此步骤?
stdin=$(cat <&0)
请注意,我并不是专门寻找任何引用 /dev/ 的解决方案,因为我希望它可以在 chroot 中使用,无论 /dev/ 是否已安装(如果可能)。
linux bash cat stdin
bash ×1
cat ×1
linux ×1
stdin ×1