Closed a4lg closed 10 months ago
Whether &> /dev/null
works as a redirection from stdout
and stderr
to /dev/null
depends on the /bin/sh
installed on the system.
Makefile
all:
./sample.sh &> /dev/null; echo $$?
.PHONY: all
sample.sh
#! /bin/sh
sleep 10
echo TO_STDOUT
echo TO_STDERR 1>&2
exit 1
/bin/sh
is Bash.
&> /dev/null
works as a redirection as the developer intended. Running make
prints 1
after ten seconds.
/bin/sh
is Dash (Debian Almquist Shell), a lightweight shell interpreter which conforms to POSIX and implements a very few extensions (compared to Bash or Zsh).
&> /dev/null
does not work as intended. Running make
prints 0
immediately and TO_STDOUT
and TO_STDERR
(both should be redirected) are printed to the console after ten seconds (and even after make
exits!).
&> /dev/null
works as a redirection fromstdout
andstderr
to/dev/null
in Bash but not in POSIX shell (considered as an asynchronous execution and the result of thecommand
command cannot be retrieved).As a result, it always assumes that Docker always exists.
This commit makes the redirection robust and portable (uses
>/dev/null 2>&1
instead, makes it possible to detect "no Docker" condition correctly).I didn't meant to do that but it seems this commit also appends a new line character to
Makefile
's EOF.