Why stdin is required to be overwritten in SSH?

Jin Li lijin.abc at gmail.com
Wed Oct 19 04:34:27 AEDT 2016


Hi SSH,

I have put the ssh command in `script.sh`, with the code:

~~~
#!/usr/bin/env bash
ssh -q server date
~~~

And I have one `main.sh` to call `script.sh` as below.

~~~
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:

while read -r run
do
./script.sh
done < <(seq 10)
~~~

The `script.sh` can be called only once, say

~~~
$ ./main.sh
Tue Oct 18 12:26:05 CDT 2016
~~~

But 10 runs are expected.

If I modify the stdin when calling, like `main1.sh` as below.

~~~
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:

while read -r run
do
./script.sh < /dev/null
done < <(seq 10)
~~~

It will return the right 10 calling.

~~~
$ ./main1.sh
Tue Oct 18 12:28:24 CDT 2016
Tue Oct 18 12:28:24 CDT 2016
Tue Oct 18 12:28:25 CDT 2016
Tue Oct 18 12:28:25 CDT 2016
Tue Oct 18 12:28:26 CDT 2016
Tue Oct 18 12:28:26 CDT 2016
Tue Oct 18 12:28:27 CDT 2016
Tue Oct 18 12:28:27 CDT 2016
Tue Oct 18 12:28:28 CDT 2016
Tue Oct 18 12:28:29 CDT 2016
~~~

Could you tell me why `stdin` needs to be overwritten in SSH? Thanks.

My machine info is as below.

~~~
$ bash --version
GNU bash, version 4.3.42(1)-release (x86_64-apple-darwin15.0.0)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

$ ssh -V
OpenSSH_6.9p1, LibreSSL 2.1.8
~~~

Best regards,
Jin


More information about the openssh-unix-dev mailing list