I can’t wrap my head around this. Why would /dev/null be used as input to an if statement? What is the use of < /dev/null in the following?
if ( $PROG --version ) < /dev/null > /dev/null 2>&1; then
$PROG
else
echo "failed"
exit 1
fi
I (think) I understand that > /dev/null 2>&1 is just used to suppress any output from both stdout and stderr.
If
$PROGis a program that expects input fromstdin, your script might stall forever waiting for you to type something in. The use of< /dev/nullis to provide an empty input to such a program. You’re right about the>and2>&1.This snippet of script is checking to see if
$PROG --versionexits with a 0 status (success), and then runs that program without any flags. If$PROG --versionfails, the script echoes “failed” and exits.