Thread (1 message) 1 message, 1 author, 2016-06-15

Re: [PATCH v2] Re: mailinfo: allow individual e-mail files as input

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:47:12

Nicolas Sebrecht [off-list ref] writes:
It really seems like the argument has precedence to the redirection
I couldn't find any reference to this case in POSIX and I guess that the
behaviour may differ between implementations of sed.
Perhaps somebody could tell us if our hesitation is justified (or not)?
If you give file arguments, standard input is irrelevant to sed.  I bet you
do:

	$ sed -e something file

all the time, and you rely on the command not to get stuck after reading
the file because now it wants to continue reading from its stdin, which is
connected to your terminal.  Have you ever worried about having to type ^D
after every such invocation of sed?  I bet you never have ;-)

Also, your _preferred_ alternative

	{ read l1; read l2; read l3;
          ( echo "$l1"; echo "$l2"; echo "$l3"; cat | sed )
	} <"$1"

is not just simply inefficient, but is actively wrong.  The "read" can
butcher your input.  For example, try:

	$ echo "a b " | ( read l1; echo "<$l1>" )
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help