git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Makefile: fix misdirected redirections

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 5, 2016, 07:02 UTC
Message-ID
<xmqqshz035e1.fsf@gitster.mtv.corp.google.com>

In general "echo 2>&1 $msg" to redirect a possible error message that comes from 'echo' itself into the same standard output stream $msg is getting written to does not make any sense; it is not like we are expecting to see any errors out of 'echo' in these statements, and even if it were the case, there is no reason to prevent the error messages from being sent to the standard error stream.

These are clearly meant to send the argument given to echo to the standard error stream as error messages. Correctly redirect by saying "send what is written to the standard output to the standard error", i.e. "1>&2" aka ">&2".

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * There are two more uses of 2>&1 in the Makefile, and they are
   correct.
   - The one in dep_check one is used as
       dep_check = $(shell ... 2>&1; echo $$?)
     and it is an attempt to make sure that anything sent to the
     standard error is not leaked out of the shell substitution.  It
     does want to send whatever is written to the standard error
     instead written to the standard output.
   - The other is "cmp ... >/dev/null 2>&1", which is a typical way
     to squelch both the standard output and the standard error for
     any command.
 Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
index 8700db8..296f175 100644
--- a/Makefile
+++ b/Makefile
@@ -2211,10 +2211,10 @@ sparse: $(SP_OBJ)
 check: common-cmds.h
 	@if sparse; \
 	then \
-		echo 2>&1 "Use 'make sparse' instead"; \
+		echo >&2 "Use 'make sparse' instead"; \
 		$(MAKE) --no-print-directory sparse; \
 	else \
-		echo 2>&1 "Did you mean 'make test'?"; \
+		echo >&2 "Did you mean 'make test'?"; \
 		exit 1; \
 	fi
 
Message 1 of 1 in “Makefile: fix misdirected redirections”
  1. Makefile: fix misdirected redirectionsJunio C Hamano, Apr 5, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.