Revert 066aca58b4ca1d10e3a99d4ae3c9df0351bbd299...ac95a9929f07bb3e8530c400373538af4e2b748c on Template

koalaman
2015-12-07 14:24:46 -08:00
parent 266fdc217b
commit a89b80409e

@@ -1,32 +1,20 @@
## Add < /dev/null to prevent ssh from swallowing stdin. ## (Message goes here, use `code` and *foo* wisely)
The same error applies to multiple commands, like `ffmpeg` and `mplayer`.
### Problematic code: ### Problematic code:
```sh ```sh
while read -r host # Simple example of problematic code
do
ssh "$host" "uptime"
done < hosts.txt
``` ```
### Correct code: ### Correct code:
```sh ```sh
while read -r host # Simple example of above code, only fixed
do
ssh "$host" "uptime" < /dev/null
done < hosts.txt
``` ```
### Rationale: ### Rationale:
Commands that process stdin will compete with the `read` statement for input. This is especially tricky for commands you wouldn't expect reads from stdin, like `ssh .. uptime`, `ffmpeg` and `mplayer`. (An explanation of why the code is problematic and how the correct code is an improvement)
The most common symptom of this is a `while read` loop only running once, even though the input contains many lines. The is because the rest of the lines are swallowed by the offending command.
To refuse such commands input, redirect their stdin with `< /dev/null`.
### Exceptions: ### Exceptions:
None. (Cases where the user may choose to ignore this warning, if any.)