Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #263779

Re: bash vs. dash and stdin

From Greg Wooledge <greg@wooledge.org>
Newsgroups linux.debian.user
Subject Re: bash vs. dash and stdin
Date 2023-11-22 13:20 +0100
Message-ID <HCUmZ-7dhz-5@gated-at.bofh.it> (permalink)
References <HCUdk-7des-11@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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.

Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

bash vs. dash and stdin Max Nikulin <manikulin@gmail.com> - 2023-11-22 13:10 +0100
  Re: bash vs. dash and stdin Greg Wooledge <greg@wooledge.org> - 2023-11-22 13:20 +0100
    Re: bash vs. dash and stdin Max Nikulin <manikulin@gmail.com> - 2023-11-23 12:10 +0100
  Re: bash vs. dash and stdin Nicolas George <george@nsup.org> - 2023-11-22 13:20 +0100

csiph-web