Updated SC2095 (markdown)

Vidar Holen
2020-03-14 21:20:16 -07:00
parent 011e69c157
commit 6a42a6f552

@@ -1,6 +1,6 @@
## Add < /dev/null to prevent ssh from swallowing stdin. ## Use ssh -n to prevent ssh from swallowing stdin.
The same error applies to multiple commands, like `ffmpeg` and `mplayer`. The same error applies to multiple commands, like `ffmpeg -nostdin` and `mplayer -noconsolecontrols`.
### Problematic code: ### Problematic code:
@@ -16,7 +16,7 @@ done < hosts.txt
```sh ```sh
while read -r host while read -r host
do do
ssh "$host" "uptime" < /dev/null ssh -n "$host" "uptime"
done < hosts.txt done < hosts.txt
``` ```
### Rationale: ### Rationale:
@@ -25,9 +25,9 @@ Commands that process stdin will compete with the `read` statement for input. Th
The most common symptom of this is a `while read` loop only running once, even though the input contains many lines. This is because the rest of the lines are swallowed by the offending command. The most common symptom of this is a `while read` loop only running once, even though the input contains many lines. This is because the rest of the lines are swallowed by the offending command.
To refuse such commands input, redirect their stdin with `< /dev/null`. To refuse such commands input, you can use a command specific option like `ssh -n` or `ffmpeg -nostdin`.
You can also use command specific options like `ssh -n` and `mplayer -noconsolecontrols`. More generally, you can also redirect their stdin with `< /dev/null`. This works for all commands with this behavior.
### Exceptions: ### Exceptions: