Hinrik Örn Sigurðsson wrote: > Bob Proulx wrote: > > Just a reminder that ssh reads from stdin unless explicitly told to > > avoid reading from stdin. If stdin isn't going to be used then the -n > > option should be used. > > [...] > > Regardless of the resolution of the above question about bash the > > usage of ssh in the above should use 'ssh -n'. > > I'm not sure how that is helpful. 'ssh -n' closes stdin prematurely, > which means that any error from the first command ("cd /tmp") will not > be propagated to the originating host, e.g. when the directory doesn't > exist.
Any errors would be reported to stderr. Any other output would to to stdout. Closing stdin has no affect on either stderr or stdout. In order to connect stdin up to the remote command ssh needs to actively read any input and then write it off to the remote process over the socket connection. Here is an illustration of the difference. $ echo foo | { ssh localhost echo bar ; cat ;} bar Where did "foo" go? It was eaten by ssh and then lost when ssh exited. $ echo foo | { ssh -n localhost echo bar ; cat ;} bar foo There it is. Now with -n ssh did not consume it. That left it for the next process to consume. Bob