On Wed, Nov 22, 2023 at 07:06:58PM +0700, Max Nikulin wrote: > Consider a file (ssh.sh) containing a couple of commands: > > ssh localhost echo remote > echo local > > Let's try to run it (assuming key-based authorization) > > bash <ssh.sh > remote
You're trying to use stdin twice at the same time. You've got bash reading stdin to fetch commands, and you've got ssh reading stdin because that's just what ssh does. This is like <https://mywiki.wooledge.org/BashFAQ/089>. ssh grabs all of the stdin (until EOF) and leaves none for bash. > One might expect to see "local" as well. > > dash <ssh.sh > remote > local I don't know dash's internals. Maybe dash reads an entire buffer's worth of stdin at a time, instead of a command at a time as bash does. > If the script is passed as an argument, not to stdin, then output contains > "local" in both cases. Yes. In that case, bash is not competing with ssh for stdin.